sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'location'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'wave_field'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '27', '123']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'wave_field'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'WaveField'},{'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': 'wave_field'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'WaveField'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'wave_field'},{'id': '27', 'type': 'if_statement', 'children': ['28', '35', '91', '119']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'and'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'for_statement', 'children': ['37', '40', '49', '69']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'slice', 'children': ['46', '47']},{'id': '46', 'type': 'colon', 'children': []},{'id': '47', 'type': 'unary_operator', 'children': ['48'], 'value': '-'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '59']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55', '56'], 'value': '<='},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'depth_base'},{'id': '59', 'type': 'block', 'children': ['60', '68']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'depth_within'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '-'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '68', 'type': 'break_statement', 'children': []},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71', '80', '87']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '79'], 'value': '-'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'depth_within'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'elif_clause', 'children': ['92', '99']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '96'], 'value': 'and'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100', '106', '115']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'depth_within'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Location'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129', '130']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'wave_field'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'depth_within'}
def location(self, wave_field, depth=None, index=None): if not isinstance(wave_field, WaveField): wave_field = WaveField[wave_field] if index is None and depth is not None: for i, layer in enumerate(self[:-1]): if layer.depth <= depth < layer.depth_base: depth_within = depth - layer.depth break else: i = len(self) - 1 layer = self[-1] depth_within = 0 elif index is not None and depth is None: layer = self[index] i = self.index(layer) depth_within = 0 else: raise NotImplementedError return Location(i, layer, wave_field, depth_within)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Debounce'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '6', 'type': 'integer', 'children': [], 'value': '100'},{'id': '7', 'type': 'block', 'children': ['8', '12', '16', '174']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'augmented_assignment', 'children': ['10', '11'], 'value': '*='},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'max_tick'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0xFFFFFFFF'},{'id': '16', 'type': 'class_definition', 'children': ['17', '18', '20']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_decorated'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '20', 'type': 'block', 'children': ['21', '45', '151']},{'id': '21', 'type': 'function_definition', 'children': ['22', '23', '26']},{'id': '22', 'type': 'function_name', 'children': [], 'value': '__init__'},{'id': '23', 'type': 'parameters', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pigpio_cb'},{'id': '26', 'type': 'block', 'children': ['27', '33', '39']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_fn'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pigpio_cb'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'function_definition', 'children': ['46', '47', '53']},{'id': '46', 'type': 'function_name', 'children': [], 'value': '__call__'},{'id': '47', 'type': 'parameters', 'children': ['48', '49', '51']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'list_splat_pattern', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '51', 'type': 'dictionary_splat_pattern', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '53', 'type': 'block', 'children': ['54', '73', '100']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58', '65']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '64', 'type': 'integer', 'children': [], 'value': '3'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '72', 'type': 'integer', 'children': [], 'value': '2'},{'id': '73', 'type': 'if_statement', 'children': ['74', '79', '90']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '>'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tick'},{'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': 'delay'},{'id': '83', 'type': 'binary_operator', 'children': ['84', '89'], 'value': '+'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'max_tick'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '100', 'type': 'if_statement', 'children': ['101', '104', '135']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '>'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '104', 'type': 'block', 'children': ['105', '115', '129']},{'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': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_fn'},{'id': '110', 'type': 'argument_list', 'children': ['111', '113']},{'id': '111', 'type': 'list_splat', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '113', 'type': 'dictionary_splat', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': "'call passed by debouncer {} {} {}'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'call filtered out by debouncer {} {} {}'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '150']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '151', 'type': 'function_definition', 'children': ['152', '153', '159']},{'id': '152', 'type': 'function_name', 'children': [], 'value': '__get__'},{'id': '153', 'type': 'parameters', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '156', 'type': 'default_parameter', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160', '166']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '165', 'type': 'True', 'children': []},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_decorated'}
def Debounce(threshold=100): threshold *= 1000 max_tick = 0xFFFFFFFF class _decorated(object): def __init__(self, pigpio_cb): self._fn = pigpio_cb self.last = 0 self.is_method = False def __call__(self, *args, **kwargs): if self.is_method: tick = args[3] else: tick = args[2] if self.last > tick: delay = max_tick-self.last + tick else: delay = tick - self.last if delay > threshold: self._fn(*args, **kwargs) print('call passed by debouncer {} {} {}' .format(tick, self.last, threshold)) self.last = tick else: print('call filtered out by debouncer {} {} {}' .format(tick, self.last, threshold)) def __get__(self, instance, type=None): self.is_method = True return functools.partial(self, instance) return _decorated
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'adjust_thickness'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'adjust_site_atten'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'adjust_source_vel'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '25', '32', '40', '48', '54', '58', '74', '93', '124', '150', '171', '284', '298', '309', '326', '361']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'density'},{'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': 'profile'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'density'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'density'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'site_atten'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_site_atten'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '/'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'tuple', 'children': ['69', '70']},{'id': '69', 'type': 'integer', 'children': [], 'value': '4000'},{'id': '70', 'type': 'integer', 'children': [], 'value': '100'},{'id': '71', 'type': 'tuple', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'if_statement', 'children': ['75', '77']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'adjust_source_vel'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '84']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'tuple', 'children': ['85', '89']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'if_statement', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'adjust_thickness'},{'id': '95', 'type': 'block', 'children': ['96', '115']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '99', 'type': 'subscript', 'children': ['100', '103', '104']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'r_'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '104', 'type': 'list_comprehension', 'children': ['105', '112']},{'id': '105', 'type': 'list', 'children': ['106', '109'], 'value': '[t / 2, 2 * t]'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '/'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '108', 'type': 'integer', 'children': [], 'value': '2'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '*'},{'id': '110', 'type': 'integer', 'children': [], 'value': '2'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '118', 'type': 'subscript', 'children': ['119', '122', '123']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'r_'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '124', 'type': 'if_statement', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'adjust_site_atten'},{'id': '126', 'type': 'block', 'children': ['127', '139']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '130', 'type': 'subscript', 'children': ['131', '134', '135']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'r_'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '135', 'type': 'list', 'children': ['136'], 'value': '[[0.0001, 0.200]]'},{'id': '136', 'type': 'list', 'children': ['137', '138'], 'value': '[0.0001, 0.200]'},{'id': '137', 'type': 'float', 'children': [], 'value': '0.0001'},{'id': '138', 'type': 'float', 'children': [], 'value': '0.200'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '142', 'type': 'subscript', 'children': ['143', '146', '147']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'r_'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'site_atten'},{'id': '150', 'type': 'function_definition', 'children': ['151', '152', '155']},{'id': '151', 'type': 'function_name', 'children': [], 'value': 'calc_rmse'},{'id': '152', 'type': 'parameters', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'that'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '170'], 'value': '**'},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '169'], 'value': '/'},{'id': '165', 'type': '()', 'children': ['166']},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '-'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'that'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'that'},{'id': '170', 'type': 'integer', 'children': [], 'value': '2'},{'id': '171', 'type': 'function_definition', 'children': ['172', '173', '175']},{'id': '172', 'type': 'function_name', 'children': [], 'value': 'err'},{'id': '173', 'type': 'parameters', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '175', 'type': 'block', 'children': ['176', '185', '206', '218', '231', '240', '250', '258', '269', '282']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': '_slowness'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '181', 'type': 'slice', 'children': ['182', '183', '184']},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'colon', 'children': []},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '185', 'type': 'if_statement', 'children': ['186', '187', '200']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'adjust_thickness'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_thickness'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '193', 'type': 'slice', 'children': ['194', '195', '196']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '195', 'type': 'colon', 'children': []},{'id': '196', 'type': '()', 'children': ['197']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '*'},{'id': '198', 'type': 'integer', 'children': [], 'value': '2'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_thickness'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '206', 'type': 'if_statement', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'adjust_site_atten'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_site_atten'},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '216', 'type': 'unary_operator', 'children': ['217'], 'value': '-'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '223']},{'id': '220', 'type': 'pattern_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'crustal_amp'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'site_term'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': '_calc_amp'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229', '230']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'density'},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_thickness'},{'id': '230', 'type': 'identifier', 'children': [], 'value': '_slowness'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'calc'},{'id': '234', 'type': 'conditional_expression', 'children': ['235', '236', '239'], 'value': 'if'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'crustal_amp'},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '=='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'target_type'},{'id': '238', 'type': 'string', 'children': [], 'value': "'crustal_amp'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'site_term'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '*'},{'id': '244', 'type': 'integer', 'children': [], 'value': '10'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'calc_rmse'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'calc'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'augmented_assignment', 'children': ['252', '253'], 'value': '+='},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'calc_rmse'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '257', 'type': 'identifier', 'children': [], 'value': '_slowness'},{'id': '258', 'type': 'if_statement', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'adjust_thickness'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'augmented_assignment', 'children': ['263', '264'], 'value': '+='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'calc_rmse'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_thickness'},{'id': '269', 'type': 'if_statement', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'adjust_site_atten'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'augmented_assignment', 'children': ['274', '275'], 'value': '+='},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'calc_rmse'},{'id': '277', 'type': 'argument_list', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': '_site_atten'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'site_atten'},{'id': '282', 'type': 'return_statement', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'minimize'},{'id': '289', 'type': 'argument_list', 'children': ['290', '291', '292', '295']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '294', 'type': 'string', 'children': [], 'value': "'L-BFGS-B'"},{'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '301', 'type': 'subscript', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '305', 'type': 'slice', 'children': ['306', '307', '308']},{'id': '306', 'type': 'integer', 'children': [], 'value': '0'},{'id': '307', 'type': 'colon', 'children': []},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '309', 'type': 'if_statement', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'adjust_thickness'},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '315', 'type': 'subscript', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '319', 'type': 'slice', 'children': ['320', '321', '322']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '321', 'type': 'colon', 'children': []},{'id': '322', 'type': '()', 'children': ['323']},{'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '*'},{'id': '324', 'type': 'integer', 'children': [], 'value': '2'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'Profile'},{'id': '331', 'type': 'argument_list', 'children': ['332', '356']},{'id': '332', 'type': 'list_comprehension', 'children': ['333', '343']},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'Layer'},{'id': '335', 'type': 'argument_list', 'children': ['336', '339', '340']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'soil_type'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '/'},{'id': '341', 'type': 'integer', 'children': [], 'value': '1'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '343', 'type': 'for_in_clause', 'children': ['344', '348']},{'id': '344', 'type': 'pattern_list', 'children': ['345', '346', '347']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '348', 'type': 'call', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '350', 'type': 'argument_list', 'children': ['351', '354', '355']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'thickness'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'slowness'},{'id': '356', 'type': 'attribute', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'wt_depth'},{'id': '361', 'type': 'return_statement', 'children': ['362']},{'id': '362', 'type': 'tuple', 'children': ['363', '366', '367']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'motion'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'loc_input'}
def fit(self, target_type, target, adjust_thickness=False, adjust_site_atten=False, adjust_source_vel=False): density = self.profile.density nl = len(density) slowness = self.profile.slowness thickness = self.profile.thickness site_atten = self._site_atten initial = slowness bounds = 1 / np.tile((4000, 100), (nl, 1)) if not adjust_source_vel: bounds[-1] = (initial[-1], initial[-1]) if adjust_thickness: bounds = np.r_[bounds, [[t / 2, 2 * t] for t in thickness]] initial = np.r_[initial, thickness] if adjust_site_atten: bounds = np.r_[bounds, [[0.0001, 0.200]]] initial = np.r_[initial, self.site_atten] def calc_rmse(this, that): return np.mean(((this - that) / that) ** 2) def err(x): _slowness = x[0:nl] if adjust_thickness: _thickness = x[nl:(2 * nl)] else: _thickness = thickness if adjust_site_atten: self._site_atten = x[-1] crustal_amp, site_term = self._calc_amp(density, _thickness, _slowness) calc = crustal_amp if target_type == 'crustal_amp' else site_term err = 10 * calc_rmse(target, calc) err += calc_rmse(slowness, _slowness) if adjust_thickness: err += calc_rmse(thickness, _thickness) if adjust_site_atten: err += calc_rmse(self._site_atten, site_atten) return err res = minimize(err, initial, method='L-BFGS-B', bounds=bounds) slowness = res.x[0:nl] if adjust_thickness: thickness = res.x[nl:(2 * nl)] profile = Profile([ Layer(l.soil_type, t, 1 / s) for l, t, s in zip(self.profile, thickness, slowness) ], self.profile.wt_depth) return (self.motion, profile, self.loc_input)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_recipe_input'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ob'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dal'},{'id': '7', 'type': 'block', 'children': ['8', '12', '16', '20', '157', '166', '172', '212', '261', '331']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ob_query_skip'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ob_query_field'},{'id': '19', 'type': 'string', 'children': [], 'value': "'obresult'"},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '151']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ob'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ObservingBlock'},{'id': '26', 'type': 'block', 'children': ['27', '34']},{'id': '27', 'type': 'import_statement', 'children': ['28']},{'id': '28', 'type': 'aliased_import', 'children': ['29', '33']},{'id': '29', 'type': 'dotted_name', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'numina'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'obsresult'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obtype'},{'id': '34', 'type': 'for_statement', 'children': ['35', '38', '47', '145']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '58']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'obtype'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ObservationResultType'},{'id': '58', 'type': 'block', 'children': ['59', '63', '67', '78', '84', '92', '105', '113', '144']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ob_query_field'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ob_query_skip'},{'id': '66', 'type': 'True', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'query_option'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_or'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ObservationResult'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_or'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ob'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dal'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'new_or'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'query_option'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tagger'},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tagger'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117', '136']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'tagger'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118', '127']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': "'Use mode tagger to fill tags in OB'"},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'tagger'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'break_statement', 'children': []},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ob'},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ob'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'getting query fields per REQ'"},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'qfields'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'for_statement', 'children': ['173', '176', '185']},{'id': '173', 'type': 'pattern_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '176', 'type': 'call', 'children': ['177', '184']},{'id': '177', 'type': 'attribute', 'children': ['178', '183']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'block', 'children': ['186', '194', '205']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'tag_n'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'tag_names'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '201']},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204']},{'id': '202', 'type': 'string', 'children': [], 'value': '"%s has these query fields %s"'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'tag_n'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'qfields'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'tag_n'},{'id': '212', 'type': 'if_statement', 'children': ['213', '218']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '217'], 'value': 'is'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '217', 'type': 'None', 'children': []},{'id': '218', 'type': 'block', 'children': ['219', '228', '238']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'running recipe tagger'"},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '235']},{'id': '230', 'type': 'attribute', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'string', 'children': [], 'value': "'with query fields %s'"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'qfields'},{'id': '238', 'type': 'if_statement', 'children': ['239', '240', '253']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'qfields'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'obsres_extractor'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'qfields'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '260', 'type': 'dictionary', 'children': []},{'id': '261', 'type': 'for_statement', 'children': ['262', '265', '274']},{'id': '262', 'type': 'pattern_list', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '265', 'type': 'call', 'children': ['266', '273']},{'id': '266', 'type': 'attribute', 'children': ['267', '272']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '271', 'type': 'argument_list', 'children': []},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'try_statement', 'children': ['276', '318']},{'id': '276', 'type': 'block', 'children': ['277', '288']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'query_option'},{'id': '280', 'type': 'call', 'children': ['281', '286']},{'id': '281', 'type': 'attribute', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '288', 'type': 'if_statement', 'children': ['289', '294', '301']},{'id': '289', 'type': 'boolean_operator', 'children': ['290', '293'], 'value': 'and'},{'id': '290', 'type': 'comparison_operator', 'children': ['291', '292'], 'value': '=='},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ob_query_field'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'ob_query_skip'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '301', 'type': 'else_clause', 'children': ['302']},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '308']},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314', '315']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'dal'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'obsres'},{'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'query_option'},{'id': '318', 'type': 'except_clause', 'children': ['319', '323']},{'id': '319', 'type': 'as_pattern', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'NoResultFound'},{'id': '321', 'type': 'as_pattern_target', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'notfound'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'on_query_not_found'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'notfound'},{'id': '331', 'type': 'return_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'create_input'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'dictionary_splat', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'result'}
def build_recipe_input(self, ob, dal): result = {} ob_query_skip = False ob_query_field = 'obresult' if isinstance(ob, ObservingBlock): import numina.types.obsresult as obtype for key, req in self.requirements().items(): if isinstance(req.type, obtype.ObservationResultType): ob_query_field = key ob_query_skip = True query_option = self.query_options.get(key) new_or = ObservationResult() new_or.__dict__ = ob.__dict__ obsres = req.query(dal, new_or, options=query_option) tagger = self.mode.tagger if tagger is not None: self.logger.debug('Use mode tagger to fill tags in OB') obsres.tags = tagger(obsres) else: obsres.tags = None break else: obsres = ob else: obsres = ob self.logger.debug('getting query fields per REQ') qfields = set() for key, req in self.requirements().items(): tag_n = req.tag_names() self.logger.debug("%s has these query fields %s", key, tag_n) qfields.update(tag_n) if obsres.tags is None: self.logger.debug('running recipe tagger') self.logger.debug('with query fields %s', qfields) if qfields: obsres.tags = self.obsres_extractor(obsres, qfields) else: obsres.tags = {} for key, req in self.requirements().items(): try: query_option = self.query_options.get(key) if key == ob_query_field and ob_query_skip: result[key] = obsres else: result[key] = req.query(dal, obsres, options=query_option) except NoResultFound as notfound: req.on_query_not_found(notfound) return self.create_input(**result)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'subsets_of_fileinfo_from_txt'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'block', 'children': ['6', '26', '49', '53', '57', '61', '65', '69', '73', '77', '290', '299']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '25'], 'value': '+'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'},{'id': '23', 'type': 'string', 'children': [], 'value': '"File "'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '25', 'type': 'string', 'children': [], 'value': '" not found!"'},{'id': '26', 'type': 'with_statement', 'children': ['27', '36']},{'id': '27', 'type': 'with_clause', 'children': ['28']},{'id': '28', 'type': 'with_item', 'children': ['29']},{'id': '29', 'type': 'as_pattern', 'children': ['30', '34']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '34', 'type': 'as_pattern_target', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'file_content'},{'id': '40', 'type': 'call', 'children': ['41', '48']},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'dict_of_subsets_of_fileinfo'},{'id': '52', 'type': 'dictionary', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sublist_of_fileinfo'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'idict'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ifiles'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'nfiles'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sublist_finished'},{'id': '76', 'type': 'True', 'children': []},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '80']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'file_content'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'if_statement', 'children': ['82', '88']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '87'], 'value': '>'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'if_statement', 'children': ['90', '98', '156']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94', '96', '97'], 'value': '!='},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'ERROR', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'if'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'if_statement', 'children': ['100', '105', '149']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '=='},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '105', 'type': 'block', 'children': ['106', '123', '137', '141', '145']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'nfiles'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'subscript', 'children': ['113', '122']},{'id': '113', 'type': 'call', 'children': ['114', '121']},{'id': '114', 'type': 'attribute', 'children': ['115', '120']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '117', 'type': 'slice', 'children': ['118', '119']},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '126', 'type': 'subscript', 'children': ['127', '136']},{'id': '127', 'type': 'call', 'children': ['128', '135']},{'id': '128', 'type': 'attribute', 'children': ['129', '134']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '131', 'type': 'slice', 'children': ['132', '133']},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'colon', 'children': []},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sublist_of_fileinfo'},{'id': '140', 'type': 'list', 'children': [], 'value': '[]'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ifiles'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sublist_finished'},{'id': '148', 'type': 'False', 'children': []},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': '"Expected @ symbol not found!"'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158', '170', '178', '184', '206', '226', '237', '241']},{'id': '158', 'type': 'if_statement', 'children': ['159', '164']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': '=='},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'},{'id': '163', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'raise_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': '"Unexpected @ symbol found!"'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'tmplist'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'tmplist'},{'id': '183', 'type': 'integer', 'children': [], 'value': '0'},{'id': '184', 'type': 'if_statement', 'children': ['185', '191', '200']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '190'], 'value': '>'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'tmplist'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'tmpinfo'},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'tmplist'},{'id': '197', 'type': 'slice', 'children': ['198', '199']},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'tmpinfo'},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '216']},{'id': '207', 'type': 'not_operator', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '214']},{'id': '209', 'type': 'attribute', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'raise_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'binary_operator', 'children': ['222', '225'], 'value': '+'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '+'},{'id': '223', 'type': 'string', 'children': [], 'value': '"File "'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '225', 'type': 'string', 'children': [], 'value': '" not found!"'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sublist_of_fileinfo'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'FileInfo'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'tmpinfo'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'augmented_assignment', 'children': ['239', '240'], 'value': '+='},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ifiles'},{'id': '240', 'type': 'integer', 'children': [], 'value': '1'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '=='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ifiles'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'nfiles'},{'id': '245', 'type': 'block', 'children': ['246', '252', '258', '264', '270', '274', '278', '282', '286']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '251']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dict_of_subsets_of_fileinfo'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'idict'},{'id': '251', 'type': 'dictionary', 'children': []},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'tmpdict'},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'dict_of_subsets_of_fileinfo'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'idict'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '263']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'tmpdict'},{'id': '262', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tmpdict'},{'id': '268', 'type': 'string', 'children': [], 'value': "'list_of_fileinfo'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sublist_of_fileinfo'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'augmented_assignment', 'children': ['272', '273'], 'value': '+='},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'idict'},{'id': '273', 'type': 'integer', 'children': [], 'value': '1'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '277', 'type': 'None', 'children': []},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'sublist_of_fileinfo'},{'id': '281', 'type': 'list', 'children': [], 'value': '[]'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ifiles'},{'id': '285', 'type': 'integer', 'children': [], 'value': '0'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'sublist_finished'},{'id': '289', 'type': 'True', 'children': []},{'id': '290', 'type': 'if_statement', 'children': ['291', '293']},{'id': '291', 'type': 'not_operator', 'children': ['292']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'sublist_finished'},{'id': '293', 'type': 'block', 'children': ['294']},{'id': '294', 'type': 'raise_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'string', 'children': [], 'value': '"Unexpected end of sublist of files."'},{'id': '299', 'type': 'return_statement', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'dict_of_subsets_of_fileinfo'}
def subsets_of_fileinfo_from_txt(filename): if not os.path.isfile(filename): raise ValueError("File " + filename + " not found!") with open(filename) as f: file_content = f.read().splitlines() dict_of_subsets_of_fileinfo = {} label = None sublist_of_fileinfo = [] idict = 0 ifiles = 0 nfiles = 0 sublist_finished = True for line in file_content: if len(line) > 0: if line[0] != ' if label is None: if line[0] == "@": nfiles = int(line[1:].split()[0]) label = line[1:].split()[1] sublist_of_fileinfo = [] ifiles = 0 sublist_finished = False else: raise ValueError("Expected @ symbol not found!") else: if line[0] == "@": raise ValueError("Unexpected @ symbol found!") tmplist = line.split() tmpfile = tmplist[0] if len(tmplist) > 1: tmpinfo = tmplist[1:] else: tmpinfo = None if not os.path.isfile(tmpfile): raise ValueError("File " + tmpfile + " not found!") sublist_of_fileinfo.append(FileInfo(tmpfile, tmpinfo)) ifiles += 1 if ifiles == nfiles: dict_of_subsets_of_fileinfo[idict] = {} tmpdict = dict_of_subsets_of_fileinfo[idict] tmpdict['label'] = label tmpdict['list_of_fileinfo'] = sublist_of_fileinfo idict += 1 label = None sublist_of_fileinfo = [] ifiles = 0 sublist_finished = True if not sublist_finished: raise ValueError("Unexpected end of sublist of files.") return dict_of_subsets_of_fileinfo
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify_refresh'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '18', '27', '37', '67', '76', '88', '123', '179']},{'id': '7', 'type': 'if_statement', 'children': ['8', '12']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'allow_refresh'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'raise_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'InvalidTokenError'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'Token refresh is disabled'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'token'},{'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_jwt'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'InvalidTokenError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'Token not found'"},{'id': '37', 'type': 'try_statement', 'children': ['38', '51', '59']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'decode_jwt'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'verify_expiration_on_refresh'},{'id': '51', 'type': 'except_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'DecodeError'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'DecodeError'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': "'Token could not be decoded'"},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ExpiredSignatureError'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'raise_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ExpiredSignatureError'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': "'Token has expired'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'userid'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_userid'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'userid'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'raise_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'MissingRequiredClaimError'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'userid_claim'},{'id': '88', 'type': 'if_statement', 'children': ['89', '94']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': 'is'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'refresh_nonce_handler'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'block', 'children': ['95', '105']},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'},{'id': '97', 'type': 'string', 'children': [], 'value': "'nonce'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'MissingRequiredClaimError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'nonce'"},{'id': '105', 'type': 'if_statement', 'children': ['106', '117']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '114'], 'value': '!='},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'refresh_nonce_handler'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'userid'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '116', 'type': 'string', 'children': [], 'value': "'nonce'"},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'raise_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'InvalidTokenError'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'Refresh nonce is not valid'"},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': 'is'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'refresh_delta'},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'block', 'children': ['130', '140', '155', '164']},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'},{'id': '132', 'type': 'string', 'children': [], 'value': "'refresh_until'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'raise_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'MissingRequiredClaimError'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': "'refresh_until'"},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'timegm'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '154']},{'id': '147', 'type': 'attribute', 'children': ['148', '153']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'utcnow'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'utctimetuple'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'refresh_until'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'claims_set'},{'id': '163', 'type': 'string', 'children': [], 'value': "'refresh_until'"},{'id': '164', 'type': 'if_statement', 'children': ['165', '173']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '<'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'refresh_until'},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '-'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'leeway'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'raise_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ExpiredSignatureError'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': "'Refresh nonce has expired'"},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'userid'}
def verify_refresh(self, request): if not self.allow_refresh: raise InvalidTokenError('Token refresh is disabled') token = self.get_jwt(request) if token is None: raise InvalidTokenError('Token not found') try: claims_set = self.decode_jwt( token, self.verify_expiration_on_refresh ) except DecodeError: raise DecodeError('Token could not be decoded') except ExpiredSignatureError: raise ExpiredSignatureError('Token has expired') userid = self.get_userid(claims_set) if userid is None: raise MissingRequiredClaimError(self.userid_claim) if self.refresh_nonce_handler is not None: if 'nonce' not in claims_set: raise MissingRequiredClaimError('nonce') if self.refresh_nonce_handler(request, userid) != claims_set['nonce']: raise InvalidTokenError('Refresh nonce is not valid') if self.refresh_delta is not None: if 'refresh_until' not in claims_set: raise MissingRequiredClaimError('refresh_until') now = timegm(datetime.utcnow().utctimetuple()) refresh_until = int(claims_set['refresh_until']) if refresh_until < (now - self.leeway): raise ExpiredSignatureError('Refresh nonce has expired') return userid
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_default_terminal'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fallback'},{'id': '9', 'type': 'identifier', 'children': [], 'value': '_UNSPECIFIED'},{'id': '10', 'type': 'block', 'children': ['11', '22', '31', '35', '44', '77', '90', '96', '103']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '14', 'type': 'None', 'children': []},{'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': 'environ'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'},{'id': '24', 'type': 'string', 'children': [], 'value': '"PIAS_OPT_TERMINAL"'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '30', 'type': 'string', 'children': [], 'value': '"PIAS_OPT_TERMINAL"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'colorterm'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '"COLORTERM"'},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '51']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '46', 'type': 'tuple', 'children': ['47', '48', '49', '50']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'colorterm'},{'id': '48', 'type': 'string', 'children': [], 'value': '"gnome-terminal"'},{'id': '49', 'type': 'string', 'children': [], 'value': '"konsole"'},{'id': '50', 'type': 'string', 'children': [], 'value': '"xterm"'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'block', 'children': ['57', '65']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'find_executable'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ancestor'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_ancestor_processes'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ancestor'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ancestor'},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'terminals'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'fallback'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_UNSPECIFIED'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'fallback'},{'id': '103', 'type': 'raise_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': '"Could not find a terminal"'}
def get_default_terminal(environ=None, fallback=_UNSPECIFIED): if environ is None: environ = os.environ if "PIAS_OPT_TERMINAL" in environ: return environ["PIAS_OPT_TERMINAL"] terminals = [] colorterm = environ.get("COLORTERM") for filename in (colorterm, "gnome-terminal", "konsole", "xterm"): if filename is not None: filepath = find_executable(filename, environ) if filepath is not None: terminals.append(filepath) for ancestor in get_ancestor_processes(): if ancestor in terminals: return ancestor for term in terminals: return term if fallback is not _UNSPECIFIED: return fallback raise ValueError("Could not find a terminal")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bitset'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'bases'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'BitSet'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '29', '51', '66', '88', '107', '125', '143']},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'binary_operator', 'children': ['27', '28'], 'value': '%'},{'id': '27', 'type': 'string', 'children': [], 'value': "'empty bitset name: %r'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'if_statement', 'children': ['30', '43']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '37'], 'value': 'or'},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '36', 'type': 'string', 'children': [], 'value': "'__getitem__'"},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '42', 'type': 'string', 'children': [], 'value': "'__len__'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'},{'id': '49', 'type': 'string', 'children': [], 'value': "'non-sequence bitset members: %r'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'},{'id': '63', 'type': 'string', 'children': [], 'value': "'less than one bitset member: %r'"},{'id': '64', 'type': 'tuple', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '66', 'type': 'if_statement', 'children': ['67', '79']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '75'], 'value': '!='},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'string', 'children': [], 'value': "'bitset members contains duplicates: %r'"},{'id': '86', 'type': 'tuple', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '88', 'type': 'if_statement', 'children': ['89', '99']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'MemberBitsMeta'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': "'base does not subclass bitset.bases: %r'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '110', 'type': 'call', 'children': ['111', '122']},{'id': '111', 'type': 'attribute', 'children': ['112', '121']},{'id': '112', 'type': 'dictionary', 'children': ['113', '116']},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'False', 'children': []},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'pair', 'children': ['117', '118']},{'id': '117', 'type': 'True', 'children': []},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '128', 'type': 'call', 'children': ['129', '140']},{'id': '129', 'type': 'attribute', 'children': ['130', '139']},{'id': '130', 'type': 'dictionary', 'children': ['131', '134']},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'False', 'children': []},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'pair', 'children': ['135', '136']},{'id': '135', 'type': 'True', 'children': []},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_make_subclass'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151', '154']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'listcls'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'tuplecls'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tuple'}
def bitset(name, members, base=bases.BitSet, list=False, tuple=False): if not name: raise ValueError('empty bitset name: %r' % name) if not hasattr(members, '__getitem__') or not hasattr(members, '__len__'): raise ValueError('non-sequence bitset members: %r' % members) if not len(members): raise ValueError('less than one bitset member: %r' % (members,)) if len(set(members)) != len(members): raise ValueError('bitset members contains duplicates: %r' % (members,)) if not issubclass(base.__class__, meta.MemberBitsMeta): raise ValueError('base does not subclass bitset.bases: %r' % base) list = {False: None, True: series.List}.get(list, list) tuple = {False: None, True: series.Tuple}.get(tuple, tuple) return base._make_subclass(name, members, listcls=list, tuplecls=tuple)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_split_refextract_authors_str'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'authors_str'},{'id': '5', 'type': 'block', 'children': ['6', '25', '29', '33', '144', '154', '182', '202']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'author_seq'},{'id': '9', 'type': 'generator_expression', 'children': ['10', '15', '23']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'RE_SPLIT_AUTH'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'authors_str'},{'id': '23', 'type': 'if_clause', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '28', 'type': 'list', 'children': [], 'value': '[]'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '32', 'type': 'string', 'children': [], 'value': "''"},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'author_seq'},{'id': '36', 'type': 'block', 'children': ['37', '62', '76', '90', '104']},{'id': '37', 'type': 'if_statement', 'children': ['38', '46']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'ignore'"},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '73']},{'id': '70', 'type': 'string', 'children': [], 'value': "r'\\(|\\)'"},{'id': '71', 'type': 'string', 'children': [], 'value': "''"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86', '87']},{'id': '84', 'type': 'string', 'children': [], 'value': "r'^[\\W\\d]+'"},{'id': '85', 'type': 'string', 'children': [], 'value': "''"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100', '101']},{'id': '98', 'type': 'string', 'children': [], 'value': "r'[^.\\w]+$'"},{'id': '99', 'type': 'string', 'children': [], 'value': "''"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '104', 'type': 'if_statement', 'children': ['105', '111', '128']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'RE_INITIALS_ONLY'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'augmented_assignment', 'children': ['114', '115'], 'value': '+='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'},{'id': '116', 'type': 'string', 'children': [], 'value': "', '"},{'id': '117', 'type': 'call', 'children': ['118', '125']},{'id': '118', 'type': 'attribute', 'children': ['119', '124']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'. '"},{'id': '127', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '140']},{'id': '130', 'type': 'if_statement', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'current'},{'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': 'res'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '144', 'type': 'if_statement', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'current'},{'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': 'res'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '157', 'type': 'list', 'children': ['158', '164', '173'], 'value': "[\n lambda a: a == 'ed',\n lambda a: a.startswith(','),\n lambda a: len(a) == 1\n ]"},{'id': '158', 'type': 'lambda', 'children': ['159', '161']},{'id': '159', 'type': 'lambda_parameters', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '=='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '163', 'type': 'string', 'children': [], 'value': "'ed'"},{'id': '164', 'type': 'lambda', 'children': ['165', '167']},{'id': '165', 'type': 'lambda_parameters', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': "','"},{'id': '173', 'type': 'lambda', 'children': ['174', '176']},{'id': '174', 'type': 'lambda_parameters', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '181'], 'value': '=='},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '181', 'type': 'integer', 'children': [], 'value': '1'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '185', 'type': 'list_comprehension', 'children': ['186', '187', '190']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '187', 'type': 'for_in_clause', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '190', 'type': 'if_clause', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '193', 'type': 'generator_expression', 'children': ['194', '199']},{'id': '194', 'type': 'not_operator', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'res'}
def _split_refextract_authors_str(authors_str): author_seq = (x.strip() for x in RE_SPLIT_AUTH.split(authors_str) if x) res = [] current = '' for author in author_seq: if not isinstance(author, six.text_type): author = six.text_type(author.decode('utf8', 'ignore')) author = re.sub(r'\(|\)', '', author, re.U) author = re.sub(r'^[\W\d]+', '', author, re.U) author = re.sub(r'[^.\w]+$', '', author, re.U) if RE_INITIALS_ONLY.match(author): current += ', ' + author.strip().replace('. ', '.') else: if current: res.append(current) current = author if current: res.append(current) filters = [ lambda a: a == 'ed', lambda a: a.startswith(','), lambda a: len(a) == 1 ] res = [r for r in res if all(not f(r) for f in filters)] return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'deduplicate'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hyperlink'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'return_multiple_columns'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '40', '57', '75', '87', '91', '98', '104', '124']},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'lambda', 'children': ['50', '52']},{'id': '50', 'type': 'lambda_parameters', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'slice', 'children': ['55', '56']},{'id': '55', 'type': 'colon', 'children': []},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '57', 'type': 'if_statement', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'hyperlink'},{'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': 'string_transformations'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'lambda', 'children': ['67', '69']},{'id': '67', 'type': 'lambda_parameters', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': '\'=HYPERLINK("{0}")\''},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'if_statement', 'children': ['76', '81']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': '[pattern_path]'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'original_pattern_path'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '96', 'type': 'slice', 'children': ['97']},{'id': '97', 'type': 'colon', 'children': []},{'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': 'pattern_path'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_process_object'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112', '115', '118', '121']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pattern_path'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'string_transformations'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'return_multiple_columns'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'return_multiple_columns'},{'id': '124', 'type': 'if_statement', 'children': ['125', '127', '130', '142', '154']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'elif_clause', 'children': ['131', '136']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': '_flatten'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '142', 'type': 'elif_clause', 'children': ['143', '149']},{'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': 'result'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156', '184', '211']},{'id': '156', 'type': 'if_statement', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '158', 'type': 'block', 'children': ['159', '168', '179']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': '"pattern_path: {0}\\n\\n"'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'original_pattern_path'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pprint'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'pformat'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'UniqueError'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '184', 'type': 'if_statement', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'deduplicate'},{'id': '186', 'type': 'block', 'children': ['187', '191', '207']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'new_result'},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'for_statement', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'if_statement', 'children': ['196', '199']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'not'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'new_result'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'new_result'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'new_result'},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'result'}
def query(pattern_path, dict_, max_length=None, strip=False, case_sensitive=False, unique=False, deduplicate=False, string_transformations=None, hyperlink=False, return_multiple_columns=False): if string_transformations is None: string_transformations = [] if max_length: string_transformations.append(lambda x: x[:max_length]) if hyperlink: string_transformations.append( lambda x: '=HYPERLINK("{0}")'.format(x)) if isinstance(pattern_path, basestring): pattern_path = [pattern_path] original_pattern_path = pattern_path pattern_path = pattern_path[:] pattern_path.reverse() result = _process_object(pattern_path, dict_, string_transformations=string_transformations, strip=strip, case_sensitive=case_sensitive, return_multiple_columns=return_multiple_columns) if not result: return None elif isinstance(result, dict): return _flatten(result) elif len(result) == 1: return result[0] else: if unique: msg = "pattern_path: {0}\n\n".format(original_pattern_path) msg = msg + pprint.pformat(dict_) raise UniqueError(msg) if deduplicate: new_result = [] for item in result: if item not in new_result: new_result.append(item) result = new_result return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_reactions'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '6', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '9', 'type': 'integer', 'children': [], 'value': '20'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '29', '33', '114', '118', '133', '154', '160', '165', '169', '382', '477', '482']},{'id': '16', 'type': 'if_statement', 'children': ['17', '22']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '19'], 'value': 'or'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '21', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'all_columns'},{'id': '28', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'for_statement', 'children': ['34', '37', '42']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'block', 'children': ['43', '50', '74']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'map_column_names'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'list', 'children': ['59', '60', '61'], 'value': "[True, 'True', 'true']"},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'string', 'children': [], 'value': "'True'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '62', 'type': 'block', 'children': ['63', '73']},{'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': 'queries'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'dictionary', 'children': ['70']},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '72', 'type': 'True', 'children': []},{'id': '73', 'type': 'continue_statement', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '86', '97']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '81'], 'value': 'or'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'float'},{'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': 'queries'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'dictionary', 'children': ['94']},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'dictionary', 'children': ['106']},{'id': '106', 'type': 'pair', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'{0}'"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '117', 'type': 'list', 'children': [], 'value': '[]'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120', '127']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '124', 'type': 'list', 'children': ['125', '126'], 'value': "['reactionSystems', 'publication']"},{'id': '125', 'type': 'string', 'children': [], 'value': "'reactionSystems'"},{'id': '126', 'type': 'string', 'children': [], 'value': "'publication'"},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '132', 'type': 'list', 'children': [], 'value': '[]'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '138', 'type': 'argument_list', 'children': ['139', '142', '145', '148', '151']},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '141', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '154', 'type': 'if_statement', 'children': ['155', '157']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "'Writing result to Reactions.db'"},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'unique_ids'},{'id': '168', 'type': 'list', 'children': [], 'value': '[]'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '176']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '175', 'type': 'string', 'children': [], 'value': "'edges'"},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'with_statement', 'children': ['178', '187']},{'id': '178', 'type': 'with_clause', 'children': ['179']},{'id': '179', 'type': 'with_item', 'children': ['180']},{'id': '180', 'type': 'as_pattern', 'children': ['181', '185']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'CathubSQLite'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'string', 'children': [], 'value': "'Reactions.db'"},{'id': '185', 'type': 'as_pattern_target', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '187', 'type': 'block', 'children': ['188', '194', '198', '234', '238', '242', '276', '298', '304', '310', '314', '320', '337', '344', '358']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '193', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '197', 'type': 'dictionary', 'children': []},{'id': '198', 'type': 'for_statement', 'children': ['199', '200', '203']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'all_columns'},{'id': '202', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '203', 'type': 'block', 'children': ['204', '210', '225']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '210', 'type': 'try_statement', 'children': ['211', '221']},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '221', 'type': 'except_clause', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'pass_statement', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '233']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '237', 'type': 'dictionary', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '241', 'type': 'dictionary', 'children': []},{'id': '242', 'type': 'for_statement', 'children': ['243', '244', '247']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '246', 'type': 'string', 'children': [], 'value': "'reactionSystems'"},{'id': '247', 'type': 'block', 'children': ['248', '256', '266']},{'id': '248', 'type': 'if_statement', 'children': ['249', '254']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '253'], 'value': '=='},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '252', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '253', 'type': 'string', 'children': [], 'value': "'N/A'"},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'continue_statement', 'children': []},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '263']},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '262', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '265', 'type': 'string', 'children': [], 'value': "'aseId'"},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '273']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '272', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'row_rs'},{'id': '275', 'type': 'string', 'children': [], 'value': "'energyCorrection'"},{'id': '276', 'type': 'if_statement', 'children': ['277', '279', '288']},{'id': '277', 'type': 'not_operator', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '279', 'type': 'block', 'children': ['280', '284']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '283', 'type': 'None', 'children': []},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '287', 'type': 'None', 'children': []},{'id': '288', 'type': 'else_clause', 'children': ['289']},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'augmented_assignment', 'children': ['292', '293'], 'value': '+='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'unique_ids'},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '297', 'type': 'argument_list', 'children': []},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '302', 'type': 'string', 'children': [], 'value': "'ase_ids'"},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '308', 'type': 'string', 'children': [], 'value': "'energy_corrections'"},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'pub_key_values'},{'id': '313', 'type': 'dictionary', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'row_p'},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '319', 'type': 'string', 'children': [], 'value': "'publication'"},{'id': '320', 'type': 'for_statement', 'children': ['321', '322', '325']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'all_columns'},{'id': '324', 'type': 'string', 'children': [], 'value': "'publications'"},{'id': '325', 'type': 'block', 'children': ['326']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '334']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'pub_key_values'},{'id': '330', 'type': 'call', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'row_p'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'write_publication'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'pub_key_values'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'assignment', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '351', 'type': 'argument_list', 'children': ['352', '355']},{'id': '352', 'type': 'subscript', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '354', 'type': 'string', 'children': [], 'value': "'chemical_composition'"},{'id': '355', 'type': 'subscript', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '357', 'type': 'string', 'children': [], 'value': "'reaction_energy'"},{'id': '358', 'type': 'if_statement', 'children': ['359', '362', '372']},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '361'], 'value': 'is'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '361', 'type': 'None', 'children': []},{'id': '362', 'type': 'block', 'children': ['363']},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'assignment', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '366', 'type': 'call', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '370', 'type': 'argument_list', 'children': ['371']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '372', 'type': 'else_clause', 'children': ['373']},{'id': '373', 'type': 'block', 'children': ['374']},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'call', 'children': ['376', '379']},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '379', 'type': 'argument_list', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'key_values'},{'id': '382', 'type': 'if_statement', 'children': ['383', '386']},{'id': '383', 'type': 'comparison_operator', 'children': ['384', '385'], 'value': 'is'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'ase_ids'},{'id': '385', 'type': 'None', 'children': []},{'id': '386', 'type': 'block', 'children': ['387']},{'id': '387', 'type': 'with_statement', 'children': ['388', '401']},{'id': '388', 'type': 'with_clause', 'children': ['389']},{'id': '389', 'type': 'with_item', 'children': ['390']},{'id': '390', 'type': 'as_pattern', 'children': ['391', '399']},{'id': '391', 'type': 'call', 'children': ['392', '397']},{'id': '392', 'type': 'attribute', 'children': ['393', '396']},{'id': '393', 'type': 'attribute', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'ase'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '397', 'type': 'argument_list', 'children': ['398']},{'id': '398', 'type': 'string', 'children': [], 'value': "'Reactions.db'"},{'id': '399', 'type': 'as_pattern_target', 'children': ['400']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'ase_db'},{'id': '401', 'type': 'block', 'children': ['402', '408', '416', '423', '431', '441', '453']},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'assignment', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'con'},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'ase_db'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'assignment', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '411', 'type': 'call', 'children': ['412', '415']},{'id': '412', 'type': 'attribute', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'con'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '415', 'type': 'argument_list', 'children': []},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'string', 'children': [], 'value': "'SELECT unique_id from systems;'"},{'id': '423', 'type': 'expression_statement', 'children': ['424']},{'id': '424', 'type': 'assignment', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'unique_ids0'},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'fetchall'},{'id': '430', 'type': 'argument_list', 'children': []},{'id': '431', 'type': 'expression_statement', 'children': ['432']},{'id': '432', 'type': 'assignment', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'unique_ids0'},{'id': '434', 'type': 'list_comprehension', 'children': ['435', '438']},{'id': '435', 'type': 'subscript', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'un'},{'id': '437', 'type': 'integer', 'children': [], 'value': '0'},{'id': '438', 'type': 'for_in_clause', 'children': ['439', '440']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'un'},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'unique_ids0'},{'id': '441', 'type': 'expression_statement', 'children': ['442']},{'id': '442', 'type': 'assignment', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'unique_ids'},{'id': '444', 'type': 'list_comprehension', 'children': ['445', '446', '449']},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'un'},{'id': '446', 'type': 'for_in_clause', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'un'},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'unique_ids'},{'id': '449', 'type': 'if_clause', 'children': ['450']},{'id': '450', 'type': 'comparison_operator', 'children': ['451', '452'], 'value': 'not'},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'un'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'unique_ids0'},{'id': '453', 'type': 'for_statement', 'children': ['454', '455', '462']},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'unique_id'},{'id': '455', 'type': 'call', 'children': ['456', '457']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '457', 'type': 'argument_list', 'children': ['458']},{'id': '458', 'type': 'call', 'children': ['459', '460']},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '460', 'type': 'argument_list', 'children': ['461']},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'unique_ids'},{'id': '462', 'type': 'block', 'children': ['463', '470']},{'id': '463', 'type': 'expression_statement', 'children': ['464']},{'id': '464', 'type': 'assignment', 'children': ['465', '466']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'atomsrow'},{'id': '466', 'type': 'call', 'children': ['467', '468']},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'get_atomsrow_by_id'},{'id': '468', 'type': 'argument_list', 'children': ['469']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'unique_id'},{'id': '470', 'type': 'expression_statement', 'children': ['471']},{'id': '471', 'type': 'call', 'children': ['472', '475']},{'id': '472', 'type': 'attribute', 'children': ['473', '474']},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'ase_db'},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '475', 'type': 'argument_list', 'children': ['476']},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'atomsrow'},{'id': '477', 'type': 'expression_statement', 'children': ['478']},{'id': '478', 'type': 'call', 'children': ['479', '480']},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '480', 'type': 'argument_list', 'children': ['481']},{'id': '481', 'type': 'string', 'children': [], 'value': "'Writing complete!'"},{'id': '482', 'type': 'return_statement', 'children': ['483']},{'id': '483', 'type': 'identifier', 'children': [], 'value': 'data'}
def get_reactions(columns='all', n_results=20, write_db=False, **kwargs): if write_db or columns == 'all': columns = all_columns['reactions'] queries = {} for key, value in kwargs.items(): key = map_column_names(key) if key == 'distinct': if value in [True, 'True', 'true']: queries.update({key: True}) continue if isinstance(value, int) or isinstance(value, float): queries.update({key: value}) else: queries.update({key: '{0}'.format(value)}) subtables = [] if write_db: subtables = ['reactionSystems', 'publication'] else: subtables = [] data = query(table='reactions', subtables=subtables, columns=columns, n_results=n_results, queries=queries) if not write_db: return data print('Writing result to Reactions.db') unique_ids = [] for row in data['reactions']['edges']: with CathubSQLite('Reactions.db') as db: row = row['node'] key_values = {} for key in all_columns['reactions']: v = row[key] try: v = json.loads(v) except BaseException: pass key_values[convert(key)] = v ase_ids = {} energy_corrections = {} for row_rs in row['reactionSystems']: if row_rs['name'] == 'N/A': continue ase_ids[row_rs['name']] = row_rs['aseId'] energy_corrections[row_rs['name']] = row_rs['energyCorrection'] if not ase_ids: ase_ids = None energy_corrections = None else: unique_ids += ase_ids.values() key_values['ase_ids'] = ase_ids key_values['energy_corrections'] = ase_ids pub_key_values = {} row_p = row['publication'] for key in all_columns['publications']: pub_key_values[convert(key)] = row_p[key] db.write_publication(pub_key_values) id = db.check(key_values['chemical_composition'], key_values['reaction_energy']) if id is None: id = db.write(key_values) else: db.update(id, key_values) if ase_ids is not None: with ase.db.connect('Reactions.db') as ase_db: con = ase_db.connection cur = con.cursor() cur.execute('SELECT unique_id from systems;') unique_ids0 = cur.fetchall() unique_ids0 = [un[0] for un in unique_ids0] unique_ids = [un for un in unique_ids if un not in unique_ids0] for unique_id in list(set(unique_ids)): atomsrow = get_atomsrow_by_id(unique_id) ase_db.write(atomsrow) print('Writing complete!') return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_atoms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '5', 'type': 'block', 'children': ['6', '13', '24', '28', '107', '156', '233']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': '=='},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '9', 'type': 'string', 'children': [], 'value': "''"},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '13', 'type': 'try_statement', 'children': ['14', '20']},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '20', 'type': 'except_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'pass_statement', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '27', 'type': 'string', 'children': [], 'value': "''"},{'id': '28', 'type': 'if_statement', 'children': ['29', '37', '97']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isalpha'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '42', '56', '67', '89']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'while_statement', 'children': ['43', '51']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isalpha'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '64', 'type': 'slice', 'children': ['65', '66']},{'id': '65', 'type': 'colon', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71', '83']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '<'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'block', 'children': ['72', '79']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '82', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '83', 'type': 'else_clause', 'children': ['84']},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '88', 'type': 'string', 'children': [], 'value': "''"},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '94', 'type': 'slice', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'colon', 'children': []},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99', '103']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '106', 'type': 'string', 'children': [], 'value': "''"},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '116']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'if_statement', 'children': ['118', '125', '148']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '139']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '138'], 'value': '-'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'augmented_assignment', 'children': ['142', '143'], 'value': '+='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '-'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '153'], 'value': '+='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'molecule'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '156', 'type': 'if_statement', 'children': ['157', '162', '170']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '=='},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'augmented_assignment', 'children': ['165', '166'], 'value': '*='},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '170', 'type': 'elif_clause', 'children': ['171', '176']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '=='},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '174', 'type': 'integer', 'children': [], 'value': '1'},{'id': '175', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '176', 'type': 'block', 'children': ['177', '184', '191', '195']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'atoms_sort'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '194', 'type': 'string', 'children': [], 'value': "''"},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '201']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '201', 'type': 'block', 'children': ['202', '220']},{'id': '202', 'type': 'for_statement', 'children': ['203', '204', '213']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '-'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'prefactor'},{'id': '212', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'augmented_assignment', 'children': ['216', '217'], 'value': '+='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'atoms_sort'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '220', 'type': 'if_statement', 'children': ['221', '226']},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '225'], 'value': '=='},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '%'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '224', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'atoms'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'atoms_sort'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '+'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'string', 'children': [], 'value': "''"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'atoms'}
def extract_atoms(molecule): if molecule == '': return molecule try: return float(molecule) except BaseException: pass atoms = '' if not molecule[0].isalpha(): i = 0 while not molecule[i].isalpha(): i += 1 prefactor = float(molecule[:i]) if prefactor < 0: prefactor = abs(prefactor) sign = '-' else: sign = '' molecule = molecule[i:] else: prefactor = 1 sign = '' for k in range(len(molecule)): if molecule[k].isdigit(): for j in range(int(molecule[k]) - 1): atoms += molecule[k - 1] else: atoms += molecule[k] if prefactor % 1 == 0: atoms *= int(prefactor) elif prefactor % 1 == 0.5: atoms_sort = sorted(atoms) N = len(atoms) atoms = '' for n in range(N): for m in range(int(prefactor - 0.5)): atoms += atoms_sort[n] if n % 2 == 0: atoms += atoms_sort[n] return sign + ''.join(sorted(atoms))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_reaction'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'reactants'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '6', 'type': 'block', 'children': ['7', '32', '57', '68', '79', '86', '93', '97', '101', '136', '160']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reactant_list'},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '29']},{'id': '11', 'type': 'call', 'children': ['12', '27']},{'id': '12', 'type': 'attribute', 'children': ['13', '26']},{'id': '13', 'type': 'call', 'children': ['14', '24']},{'id': '14', 'type': 'attribute', 'children': ['15', '23']},{'id': '15', 'type': 'subscript', 'children': ['16', '22']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'reactant'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'gas'"},{'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'reactant'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reactants'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'product_list'},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '54']},{'id': '36', 'type': 'call', 'children': ['37', '52']},{'id': '37', 'type': 'attribute', 'children': ['38', '51']},{'id': '38', 'type': 'call', 'children': ['39', '49']},{'id': '39', 'type': 'attribute', 'children': ['40', '48']},{'id': '40', 'type': 'subscript', 'children': ['41', '47']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'gas'"},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'reactant_atoms'},{'id': '60', 'type': 'list_comprehension', 'children': ['61', '65']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'extract_atoms'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'reactant'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'reactant'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reactant_list'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'product_atoms'},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '76']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'extract_atoms'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'product_list'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'reactants'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'add_atoms'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'reactant_atoms'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'add_atoms'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'product_atoms'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'r_stars'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'p_stars'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'for_statement', 'children': ['102', '105', '109']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'reactant_atoms'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'if_statement', 'children': ['111', '120', '125']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'or'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '114', 'type': 'string', 'children': [], 'value': "''"},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'in'},{'id': '116', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'reactant_list'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'augmented_assignment', 'children': ['123', '124'], 'value': '+='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'r_stars'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'elif_clause', 'children': ['126', '131']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'augmented_assignment', 'children': ['134', '135'], 'value': '+='},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'r_stars'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'product_atoms'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '144', '149']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '143', 'type': 'string', 'children': [], 'value': "''"},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'p_stars'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'elif_clause', 'children': ['150', '155']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'augmented_assignment', 'children': ['158', '159'], 'value': '+='},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'p_stars'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '160', 'type': 'assert_statement', 'children': ['161']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '171'], 'value': '=='},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "''"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'reactants'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': "''"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'products'}
def check_reaction(reactants, products): reactant_list = [reactant.split('@')[0].strip( 'star').strip('gas') for reactant in reactants] product_list = [product.split('@')[0].strip( 'star').strip('gas') for product in products] reactant_atoms = [extract_atoms(reactant) for reactant in reactant_list] product_atoms = [extract_atoms(product) for product in product_list] reactants = add_atoms(reactant_atoms) products = add_atoms(product_atoms) r_stars = 0 p_stars = 0 for i, a in enumerate(reactant_atoms): if a == '' or 'star' in reactant_list[i]: r_stars += 1 elif isinstance(a, float): r_stars += a for a in product_atoms: if a == '': p_stars += 1 elif isinstance(a, float): p_stars += a assert ''.join(sorted(reactants)) == ''.join(sorted(products))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fowler_array'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ti'},{'id': '7', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '10', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'gain'},{'id': '13', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ron'},{'id': '16', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '22', 'type': 'string', 'children': [], 'value': "'float64'"},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'saturation'},{'id': '25', 'type': 'integer', 'children': [], 'value': '65631'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '40', '50', '60', '70', '80', '90', '99', '111', '121', '137', '148', '160', '172', '181', '195', '240', '252', '261', '273', '281', '299']},{'id': '33', 'type': 'import_statement', 'children': ['34']},{'id': '34', 'type': 'aliased_import', 'children': ['35', '39']},{'id': '35', 'type': 'dotted_name', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'numina'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_nirproc'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_nirproc'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '<='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'gain'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"invalid parameter, gain <= 0.0"'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '<='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ron'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"invalid parameter, ron < 0.0"'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '<'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ti'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'raise_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': '"invalid parameter, ti < 0.0"'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '<'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'raise_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"invalid parameter, ts < 0.0"'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '<='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'saturation'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': '"invalid parameter, saturation <= 0"'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '99', 'type': 'if_statement', 'children': ['100', '105']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '!='},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '104', 'type': 'integer', 'children': [], 'value': '3'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'raise_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'fowlerdata must be 3D'"},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'npairs'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '120'], 'value': '//'},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'integer', 'children': [], 'value': '2'},{'id': '121', 'type': 'if_statement', 'children': ['122', '131']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': '!='},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '*'},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'npairs'},{'id': '126', 'type': 'subscript', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'raise_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': "'axis-0 in fowlerdata must be even'"},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ndtype'},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'newbyteorder'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'string', 'children': [], 'value': "'='"},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ndtype'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'fdtype'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'result_type'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'mdtype'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': "'uint8'"},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fshape'},{'id': '184', 'type': 'tuple', 'children': ['185', '190']},{'id': '185', 'type': 'subscript', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '194', 'type': 'integer', 'children': [], 'value': '2'},{'id': '195', 'type': 'if_statement', 'children': ['196', '199', '212']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'is'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '198', 'type': 'None', 'children': []},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'fshape'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'mdtype'},{'id': '212', 'type': 'else_clause', 'children': ['213']},{'id': '213', 'type': 'block', 'children': ['214', '228']},{'id': '214', 'type': 'if_statement', 'children': ['215', '220']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '219'], 'value': '!='},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'fshape'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'raise_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'concatenated_string', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'shape of badpixels is not '"},{'id': '227', 'type': 'string', 'children': [], 'value': "'compatible with shape of fowlerdata'"},{'id': '228', 'type': 'if_statement', 'children': ['229', '234']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': '!='},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'mdtype'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'raise_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': "'dtype of badpixels must be uint8'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'fshape'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'fdtype'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'empty_like'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'npix'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'fshape'},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'mdtype'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': '_nirproc'},{'id': '285', 'type': 'identifier', 'children': [], 'value': '_process_fowler_intl'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288', '289', '290', '291', '292', '293', '294', '295', '296', '297', '298']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'fowlerdata'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ti'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'gain'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ron'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'badpixels'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'saturation'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'npix'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '299', 'type': 'return_statement', 'children': ['300']},{'id': '300', 'type': 'expression_list', 'children': ['301', '302', '303', '304']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'npix'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'mask'}
def fowler_array(fowlerdata, ti=0.0, ts=0.0, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, normalize=False): import numina.array._nirproc as _nirproc if gain <= 0: raise ValueError("invalid parameter, gain <= 0.0") if ron <= 0: raise ValueError("invalid parameter, ron < 0.0") if ti < 0: raise ValueError("invalid parameter, ti < 0.0") if ts < 0: raise ValueError("invalid parameter, ts < 0.0") if saturation <= 0: raise ValueError("invalid parameter, saturation <= 0") fowlerdata = numpy.asarray(fowlerdata) if fowlerdata.ndim != 3: raise ValueError('fowlerdata must be 3D') npairs = fowlerdata.shape[0] // 2 if 2 * npairs != fowlerdata.shape[0]: raise ValueError('axis-0 in fowlerdata must be even') ndtype = fowlerdata.dtype.newbyteorder('=') fowlerdata = numpy.asarray(fowlerdata, dtype=ndtype) fdtype = numpy.result_type(fowlerdata.dtype, dtype) mdtype = numpy.dtype('uint8') fshape = (fowlerdata.shape[1], fowlerdata.shape[2]) if badpixels is None: badpixels = numpy.zeros(fshape, dtype=mdtype) else: if badpixels.shape != fshape: raise ValueError('shape of badpixels is not ' 'compatible with shape of fowlerdata') if badpixels.dtype != mdtype: raise ValueError('dtype of badpixels must be uint8') result = numpy.empty(fshape, dtype=fdtype) var = numpy.empty_like(result) npix = numpy.empty(fshape, dtype=mdtype) mask = badpixels.copy() _nirproc._process_fowler_intl( fowlerdata, ti, ts, gain, ron, badpixels, saturation, blank, result, var, npix, mask ) return result, var, npix, mask
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reactions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '8', 'type': 'block', 'children': ['9', '96', '107', '126', '130', '134', '138', '160', '173']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '16', 'type': 'block', 'children': ['17', '21']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '24', 'type': 'block', 'children': ['25', '36', '59']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'='"},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '=='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'if_statement', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'list', 'children': ['45', '46'], 'value': "['True', 'true']"},{'id': '45', 'type': 'string', 'children': [], 'value': "'True'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '47', 'type': 'block', 'children': ['48', '58']},{'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': 'query_dict'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'dictionary', 'children': ['55']},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'continue_statement', 'children': []},{'id': '59', 'type': 'try_statement', 'children': ['60', '78']},{'id': '60', 'type': 'block', 'children': ['61', '68']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'dictionary', 'children': ['75']},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '78', 'type': 'except_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'dictionary', 'children': ['88']},{'id': '88', 'type': 'pair', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': "'{0}'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '99'], 'value': 'and'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '>'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_reactions'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '121', '124']},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '124', 'type': 'dictionary_splat', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '126', 'type': 'if_statement', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'write_db'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'return_statement', 'children': []},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'table'},{'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': 'headers'},{'id': '137', 'type': 'list', 'children': [], 'value': '[]'},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '145']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '140', 'type': 'subscript', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '143', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '144', 'type': 'string', 'children': [], 'value': "'edges'"},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '149', 'type': 'list', 'children': ['150'], 'value': "[list(row['node'].values())]"},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '157', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '170', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '183'], 'value': '+'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'tabulate'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '183', 'type': 'string', 'children': [], 'value': "'\\n'"}
def reactions(columns, n_results, write_db, queries): if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.update({key: True}) continue try: value = int(value) query_dict.update({key: value}) except BaseException: query_dict.update({key: '{0}'.format(value)}) if write_db and n_results > 1000: print( ) data = query.get_reactions(columns=columns, n_results=n_results, write_db=write_db, **query_dict) if write_db: return table = [] headers = [] for row in data['reactions']['edges']: table += [list(row['node'].values())] headers = list(row['node'].keys()) print(tabulate(table, headers) + '\n')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'publications'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '7', 'type': 'block', 'children': ['8', '95', '110', '130', '134', '138', '248', '261']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '15', 'type': 'block', 'children': ['16', '20']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '23', 'type': 'block', 'children': ['24', '35', '58']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'='"},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '46']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'list', 'children': ['44', '45'], 'value': "['True', 'true']"},{'id': '44', 'type': 'string', 'children': [], 'value': "'True'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '46', 'type': 'block', 'children': ['47', '57']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'dictionary', 'children': ['54']},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'True', 'children': []},{'id': '57', 'type': 'continue_statement', 'children': []},{'id': '58', 'type': 'try_statement', 'children': ['59', '77']},{'id': '59', 'type': 'block', 'children': ['60', '67']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'query_dict'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'dictionary', 'children': ['74']},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '77', 'type': 'except_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'dictionary', 'children': ['87']},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'{0}'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'},{'id': '97', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'dictionary', 'children': ['107']},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '109', 'type': 'string', 'children': [], 'value': "'-year'"},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '117', 'type': 'argument_list', 'children': ['118', '121', '124', '127']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '120', 'type': 'string', 'children': [], 'value': "'publications'"},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'n_results'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'query_dict'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'table'},{'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': 'headers'},{'id': '137', 'type': 'list', 'children': [], 'value': '[]'},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '145']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '140', 'type': 'subscript', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '143', 'type': 'string', 'children': [], 'value': "'publications'"},{'id': '144', 'type': 'string', 'children': [], 'value': "'edges'"},{'id': '145', 'type': 'block', 'children': ['146', '159', '243']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '156', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'for_statement', 'children': ['160', '163', '167']},{'id': '160', 'type': 'pattern_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '181']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '175'], 'value': 'and'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '>'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '180', 'type': 'integer', 'children': [], 'value': '20'},{'id': '181', 'type': 'block', 'children': ['182', '191', '195', '199', '233', '237']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'splited'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'string', 'children': [], 'value': "' '"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '198', 'type': 'string', 'children': [], 'value': "''"},{'id': '199', 'type': 'for_statement', 'children': ['200', '201', '202']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'splited'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'if_statement', 'children': ['204', '207', '221']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '<'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '206', 'type': 'integer', 'children': [], 'value': '20'},{'id': '207', 'type': 'block', 'children': ['208', '215']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'augmented_assignment', 'children': ['210', '211'], 'value': '+='},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'augmented_assignment', 'children': ['217', '218'], 'value': '+='},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'string', 'children': [], 'value': "' '"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223', '229']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'augmented_assignment', 'children': ['225', '226'], 'value': '+='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '+'},{'id': '227', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'augmented_assignment', 'children': ['235', '236'], 'value': '+='},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '236', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '242']},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '246', 'type': 'list', 'children': ['247'], 'value': '[value]'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '258', 'type': 'string', 'children': [], 'value': "'node'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '274'], 'value': '+'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tabulate'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'tablefmt'},{'id': '273', 'type': 'string', 'children': [], 'value': '"grid"'},{'id': '274', 'type': 'string', 'children': [], 'value': "'\\n'"}
def publications(columns, n_results, queries): if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.update({key: True}) continue try: value = int(value) query_dict.update({key: value}) except BaseException: query_dict.update({key: '{0}'.format(value)}) if 'sort' not in query_dict: query_dict.update({'order': '-year'}) data = query.query(table='publications', columns=columns, n_results=n_results, queries=query_dict) table = [] headers = [] for row in data['publications']['edges']: value = list(row['node'].values()) for n, v in enumerate(value): if isinstance(v, str) and len(v) > 20: splited = v.split(' ') size = 0 sentence = '' for word in splited: if size < 20: size += len(word) sentence += ' ' + word else: sentence += '\n' + word size = 0 sentence += '\n' value[n] = sentence table += [value] headers = list(row['node'].keys()) print(tabulate(table, headers, tablefmt="grid") + '\n')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_folders'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '6', 'type': 'block', 'children': ['7', '24', '34', '54', '62', '68', '129', '251', '335', '346']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'dict_representer'},{'id': '9', 'type': 'parameters', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dumper'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'dumper'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'represent_dict'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Dumper'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'add_representer'},{'id': '29', 'type': 'argument_list', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict_representer'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'curdir'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '+'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '60', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ase_tools'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'REACTION_TEMPLATE'},{'id': '68', 'type': 'if_statement', 'children': ['69', '78']},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'with_statement', 'children': ['80', '90']},{'id': '80', 'type': 'with_clause', 'children': ['81']},{'id': '81', 'type': 'with_item', 'children': ['82']},{'id': '82', 'type': 'as_pattern', 'children': ['83', '88']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '87', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '88', 'type': 'as_pattern_target', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '90', 'type': 'block', 'children': ['91', '111', '128']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '110'], 'value': '+'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '107']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '106', 'type': 'integer', 'children': [], 'value': '4'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Dumper'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Dumper'},{'id': '110', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '127'], 'value': '+'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '126'], 'value': '+'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"Created template file: {template}\\n"'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'dictionary_splat', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'string', 'children': [], 'value': "' Please edit it and run the script again to create your folderstructure.\\n'"},{'id': '127', 'type': 'string', 'children': [], 'value': "' Run cathub make_folders --help for instructions'"},{'id': '128', 'type': 'return_statement', 'children': []},{'id': '129', 'type': 'with_statement', 'children': ['130', '139']},{'id': '130', 'type': 'with_clause', 'children': ['131']},{'id': '131', 'type': 'with_item', 'children': ['132']},{'id': '132', 'type': 'as_pattern', 'children': ['133', '137']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '137', 'type': 'as_pattern_target', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '139', 'type': 'block', 'children': ['140', '149', '155', '161', '167', '173', '179', '185', '191', '197', '203', '209', '215', '221', '227', '233', '239', '245']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '154', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '160', 'type': 'string', 'children': [], 'value': "'authors'"},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'journal'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '166', 'type': 'string', 'children': [], 'value': "'journal'"},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'volume'},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '172', 'type': 'string', 'children': [], 'value': "'volume'"},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '178', 'type': 'string', 'children': [], 'value': "'number'"},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '184', 'type': 'string', 'children': [], 'value': "'pages'"},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '190', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '196', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'publisher'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '202', 'type': 'string', 'children': [], 'value': "'publisher'"},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'doi'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '208', 'type': 'string', 'children': [], 'value': "'doi'"},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'dft_code'},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '214', 'type': 'string', 'children': [], 'value': "'DFT_code'"},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dft_functionals'},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '220', 'type': 'string', 'children': [], 'value': "'DFT_functionals'"},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'reactions'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '226', 'type': 'string', 'children': [], 'value': "'reactions'"},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'crystal_structures'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '232', 'type': 'string', 'children': [], 'value': "'crystal_structures'"},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'bulk_compositions'},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '238', 'type': 'string', 'children': [], 'value': "'bulk_compositions'"},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'facets'},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '244', 'type': 'string', 'children': [], 'value': "'facets'"},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'template_data'},{'id': '250', 'type': 'string', 'children': [], 'value': "'energy_corrections'"},{'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': 'make_folders_template'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'main'},{'id': '256', 'type': 'argument_list', 'children': ['257', '260', '275', '278', '281', '284', '287', '290', '293', '296', '299', '302', '305', '320', '323', '326', '329', '332']},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '262', 'type': 'conditional_expression', 'children': ['263', '267', '274'], 'value': 'if'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'journal'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'journal'},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'volume'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'volume'},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'publisher'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'publisher'},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'doi'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'doi'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'DFT_code'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'dft_code'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'DFT_functionals'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'dft_functionals'},{'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'reactions'},{'id': '307', 'type': 'conditional_expression', 'children': ['308', '312', '319'], 'value': 'if'},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'reactions'},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'reactions'},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'reactions'},{'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'custom_base'},{'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'bulk_compositions'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'bulk_compositions'},{'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'crystal_structures'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'crystal_structures'},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'facets'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'facets'},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'energy_corrections'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'pub_id'},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'get_pub_id'},{'id': '342', 'type': 'argument_list', 'children': ['343', '344', '345']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'string', 'children': [], 'value': '"Now dump your DFT output files into the folder, and run \'cathub folder2db {pub_id}\'"'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'dictionary_splat', 'children': ['356']},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '358', 'type': 'argument_list', 'children': []}
def make_folders(template, custom_base): def dict_representer(dumper, data): return dumper.represent_dict(data.items()) Dumper.add_representer(collections.OrderedDict, dict_representer) if custom_base is None: custom_base = os.path.abspath(os.path.curdir) template = custom_base + '/' + template template_data = ase_tools.REACTION_TEMPLATE if not os.path.exists(template): with open(template, 'w') as outfile: outfile.write( yaml.dump( template_data, indent=4, Dumper=Dumper) + '\n') print("Created template file: {template}\n".format(**locals()) + ' Please edit it and run the script again to create your folderstructure.\n' + ' Run cathub make_folders --help for instructions') return with open(template) as infile: template_data = yaml.load(infile) title = template_data['title'] authors = template_data['authors'] journal = template_data['journal'] volume = template_data['volume'] number = template_data['number'] pages = template_data['pages'] year = template_data['year'] email = template_data['email'] publisher = template_data['publisher'] doi = template_data['doi'] dft_code = template_data['DFT_code'] dft_functionals = template_data['DFT_functionals'] reactions = template_data['reactions'] crystal_structures = template_data['crystal_structures'] bulk_compositions = template_data['bulk_compositions'] facets = template_data['facets'] energy_corrections = template_data['energy_corrections'] make_folders_template.main( title=title, authors=eval(authors) if isinstance( authors, six.string_types) else authors, journal=journal, volume=volume, number=number, pages=pages, year=year, email=email, publisher=publisher, doi=doi, DFT_code=dft_code, DFT_functionals=dft_functionals, reactions=eval(reactions) if isinstance( reactions, six.string_types) else reactions, custom_base=custom_base, bulk_compositions=bulk_compositions, crystal_structures=crystal_structures, facets=facets, energy_corrections=energy_corrections ) pub_id = tools.get_pub_id(title, authors, year) print( "Now dump your DFT output files into the folder, and run 'cathub folder2db {pub_id}'".format(**locals()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'opensignals_hierarchy'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'clone'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '27', '38', '44', '62', '156', '162', '180', '210', '430']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '17', 'type': 'None', 'children': []},{'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': 'root'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'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': 'categories'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'NOTEBOOK_KEYS'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '43', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '44', 'type': 'if_statement', 'children': ['45', '54']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '68']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '64', 'type': 'list', 'children': ['65', '66', '67'], 'value': '["images", "styles", "signal_samples"]'},{'id': '65', 'type': 'string', 'children': [], 'value': '"images"'},{'id': '66', 'type': 'string', 'children': [], 'value': '"styles"'},{'id': '67', 'type': 'string', 'children': [], 'value': '"signal_samples"'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '83', '112']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'binary_operator', 'children': ['79', '82'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '81', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment\\\\"'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '83', 'type': 'block', 'children': ['84', '96', '104']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '95'], 'value': '+'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '94'], 'value': '+'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '103'], 'value': '+'},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '102', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'copytree'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '112', 'type': 'elif_clause', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '128', '140', '148']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '126', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment\\\\"'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '139'], 'value': '+'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '138'], 'value': '+'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '147'], 'value': '+'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '+'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '146', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'copytree'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '161', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment\\\\Categories"'},{'id': '162', 'type': 'if_statement', 'children': ['163', '172']},{'id': '163', 'type': 'not_operator', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '180', 'type': 'for_statement', 'children': ['181', '182', '183']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'if_statement', 'children': ['185', '198']},{'id': '185', 'type': 'not_operator', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '+'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '196', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '209'], 'value': '+'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'current_dir'},{'id': '208', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'is'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'clone'},{'id': '213', 'type': 'True', 'children': []},{'id': '214', 'type': 'block', 'children': ['215', '221', '230', '314', '321', '334', '345', '358', '369', '382', '393', '406', '417']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dir_path'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '220', 'type': 'string', 'children': [], 'value': '"\\\\notebook_code"'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'list_of_code_dirs'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'dir_path'},{'id': '230', 'type': 'for_statement', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'list_of_code_dirs'},{'id': '233', 'type': 'block', 'children': ['234', '242']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'folder_path'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '241'], 'value': '+'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '+'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '240', 'type': 'string', 'children': [], 'value': '"\\\\notebook_code\\\\"'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '242', 'type': 'if_statement', 'children': ['243', '250']},{'id': '243', 'type': 'boolean_operator', 'children': ['244', '247'], 'value': 'and'},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '!='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '246', 'type': 'string', 'children': [], 'value': '"MainFiles"'},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': '!='},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '249', 'type': 'string', 'children': [], 'value': '"__pycache__"'},{'id': '250', 'type': 'block', 'children': ['251', '260']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'list_of_code_files'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'folder_path'},{'id': '260', 'type': 'for_statement', 'children': ['261', '262', '263']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'list_of_code_files'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'if_statement', 'children': ['265', '268']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': '!='},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '267', 'type': 'string', 'children': [], 'value': '"__pycache__"'},{'id': '268', 'type': 'block', 'children': ['269', '285', '296', '305']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '272', 'type': 'call', 'children': ['273', '278']},{'id': '273', 'type': 'attribute', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'spec_from_file_location'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '280', 'type': 'binary_operator', 'children': ['281', '284'], 'value': '+'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '+'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'folder_path'},{'id': '283', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'foo'},{'id': '288', 'type': 'call', 'children': ['289', '294']},{'id': '289', 'type': 'attribute', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'module_from_spec'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '303']},{'id': '298', 'type': 'attribute', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'exec_module'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'foo'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'foo'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '+'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '313', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'main_page'},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'notebook'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'string', 'children': [], 'value': '"Main_Files_By_Category"'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'main_page'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'write_to_file'},{'id': '326', 'type': 'argument_list', 'children': ['327', '330', '331']},{'id': '327', 'type': 'binary_operator', 'children': ['328', '329'], 'value': '+'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '329', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '330', 'type': 'string', 'children': [], 'value': '"opensignalstools"'},{'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '333', 'type': 'False', 'children': []},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'by_difficulty'},{'id': '337', 'type': 'call', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'notebook'},{'id': '339', 'type': 'argument_list', 'children': ['340', '341', '342']},{'id': '340', 'type': 'string', 'children': [], 'value': '"Main_Files_By_Difficulty"'},{'id': '341', 'type': 'string', 'children': [], 'value': '"Notebooks Grouped by Difficulty"'},{'id': '342', 'type': 'keyword_argument', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'notebook_description'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'DESCRIPTION_GROUP_BY'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'by_difficulty'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'write_to_file'},{'id': '350', 'type': 'argument_list', 'children': ['351', '354', '355']},{'id': '351', 'type': 'binary_operator', 'children': ['352', '353'], 'value': '+'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '353', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '354', 'type': 'string', 'children': [], 'value': '"by_diff"'},{'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '357', 'type': 'False', 'children': []},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'by_tags'},{'id': '361', 'type': 'call', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'notebook'},{'id': '363', 'type': 'argument_list', 'children': ['364', '365', '366']},{'id': '364', 'type': 'string', 'children': [], 'value': '"Main_Files_By_Tag"'},{'id': '365', 'type': 'string', 'children': [], 'value': '"Notebooks Grouped by Tag Values"'},{'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'notebook_description'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'DESCRIPTION_GROUP_BY'},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'by_tags'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'write_to_file'},{'id': '374', 'type': 'argument_list', 'children': ['375', '378', '379']},{'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '+'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '377', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '378', 'type': 'string', 'children': [], 'value': '"by_tag"'},{'id': '379', 'type': 'keyword_argument', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '381', 'type': 'False', 'children': []},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'assignment', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'by_signal_type'},{'id': '385', 'type': 'call', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'notebook'},{'id': '387', 'type': 'argument_list', 'children': ['388', '389', '390']},{'id': '388', 'type': 'string', 'children': [], 'value': '"Main_Files_By_Signal_Type"'},{'id': '389', 'type': 'string', 'children': [], 'value': '"Notebooks Grouped by Signal Type"'},{'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'notebook_description'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'DESCRIPTION_GROUP_BY'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'by_signal_type'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'write_to_file'},{'id': '398', 'type': 'argument_list', 'children': ['399', '402', '403']},{'id': '399', 'type': 'binary_operator', 'children': ['400', '401'], 'value': '+'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '401', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '402', 'type': 'string', 'children': [], 'value': '"by_signal_type"'},{'id': '403', 'type': 'keyword_argument', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '405', 'type': 'False', 'children': []},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'assignment', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'signal_samples'},{'id': '409', 'type': 'call', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'notebook'},{'id': '411', 'type': 'argument_list', 'children': ['412', '413', '414']},{'id': '412', 'type': 'string', 'children': [], 'value': '"Main_Files_Signal_Samples"'},{'id': '413', 'type': 'string', 'children': [], 'value': '"Signal Samples Library"'},{'id': '414', 'type': 'keyword_argument', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'notebook_description'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'DESCRIPTION_SIGNAL_SAMPLES'},{'id': '417', 'type': 'expression_statement', 'children': ['418']},{'id': '418', 'type': 'call', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'signal_samples'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'write_to_file'},{'id': '422', 'type': 'argument_list', 'children': ['423', '426', '427']},{'id': '423', 'type': 'binary_operator', 'children': ['424', '425'], 'value': '+'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '425', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'},{'id': '426', 'type': 'string', 'children': [], 'value': '"signal_samples"'},{'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '429', 'type': 'False', 'children': []},{'id': '430', 'type': 'return_statement', 'children': ['431']},{'id': '431', 'type': 'binary_operator', 'children': ['432', '433'], 'value': '+'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '433', 'type': 'string', 'children': [], 'value': '"\\\\opensignalstools_environment"'}
def opensignals_hierarchy(root=None, update=False, clone=False): if root is None: root = os.getcwd() categories = list(NOTEBOOK_KEYS.keys()) current_dir = root + "\\opensignalstools_environment" if not os.path.isdir(current_dir): os.makedirs(current_dir) for var in ["images", "styles", "signal_samples"]: if not os.path.isdir(root + "\\opensignalstools_environment\\" + var): src = os.getcwd() + "\\" + var destination = current_dir + "\\" + var shutil.copytree(src, destination) elif update is True: shutil.rmtree(root + "\\opensignalstools_environment\\" + var) src = os.getcwd() + "\\" + var destination = current_dir + "\\" + var shutil.copytree(src, destination) current_dir = root + "\\opensignalstools_environment\\Categories" if not os.path.isdir(current_dir): os.makedirs(current_dir) for category in categories: if not os.path.isdir(current_dir + "\\" + category): os.makedirs(current_dir + "\\" + category) if clone is True: dir_path = root + "\\notebook_code" list_of_code_dirs = os.listdir(dir_path) for folder in list_of_code_dirs: folder_path = root + "\\notebook_code\\" + folder if folder != "MainFiles" and folder != "__pycache__": list_of_code_files = os.listdir(folder_path) for file in list_of_code_files: if file != "__pycache__": spec = importlib.util.spec_from_file_location(file, folder_path + "\\" + file) foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo) foo.run(root + "\\opensignalstools_environment") main_page = notebook("Main_Files_By_Category") main_page.write_to_file(root + "\\opensignalstools_environment", "opensignalstools", footer=False) by_difficulty = notebook("Main_Files_By_Difficulty", "Notebooks Grouped by Difficulty", notebook_description=DESCRIPTION_GROUP_BY) by_difficulty.write_to_file(root + "\\opensignalstools_environment", "by_diff", footer=False) by_tags = notebook("Main_Files_By_Tag", "Notebooks Grouped by Tag Values", notebook_description=DESCRIPTION_GROUP_BY) by_tags.write_to_file(root + "\\opensignalstools_environment", "by_tag", footer=False) by_signal_type = notebook("Main_Files_By_Signal_Type", "Notebooks Grouped by Signal Type", notebook_description=DESCRIPTION_GROUP_BY) by_signal_type.write_to_file(root + "\\opensignalstools_environment", "by_signal_type", footer=False) signal_samples = notebook("Main_Files_Signal_Samples", "Signal Samples Library", notebook_description=DESCRIPTION_SIGNAL_SAMPLES) signal_samples.write_to_file(root + "\\opensignalstools_environment", "signal_samples", footer=False) return root + "\\opensignalstools_environment"
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_notebook_by_tag_body'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'notebook_object'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dict_by_tag'},{'id': '6', 'type': 'block', 'children': ['7', '18', '24']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tag_keys'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dict_by_tag'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tag_keys'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'tag_keys'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'if_statement', 'children': ['29', '36']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '35'], 'value': 'not'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'SIGNAL_TYPE_LIST'},{'id': '36', 'type': 'block', 'children': ['37', '43', '53', '154', '158']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'group_tag_code'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'TAG_TABLE_HEADER'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': '"Tag i"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'notebook_file'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dict_by_tag'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '58', 'type': 'block', 'children': ['59', '68', '75', '89', '103', '127', '136']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'split_path'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'notebook_file'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"\\\\"'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'notebook_type'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'split_path'},{'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'},{'id': '74', 'type': 'integer', 'children': [], 'value': '2'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'notebook_name'},{'id': '78', 'type': 'subscript', 'children': ['79', '88']},{'id': '79', 'type': 'call', 'children': ['80', '86']},{'id': '80', 'type': 'attribute', 'children': ['81', '85']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'split_path'},{'id': '83', 'type': 'unary_operator', 'children': ['84'], 'value': '-'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'notebook_title'},{'id': '92', 'type': 'subscript', 'children': ['93', '102']},{'id': '93', 'type': 'call', 'children': ['94', '100']},{'id': '94', 'type': 'attribute', 'children': ['95', '99']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'split_path'},{'id': '97', 'type': 'unary_operator', 'children': ['98'], 'value': '-'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'augmented_assignment', 'children': ['105', '106'], 'value': '+='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '126'], 'value': '+'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '121'], 'value': '+'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '118'], 'value': '+'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111', '112'], 'value': '+'},{'id': '110', 'type': 'string', 'children': [], 'value': '"\\t<tr>\\n\\t\\t<td width=\'20%\' class=\'header_image_color_"'},{'id': '111', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'NOTEBOOK_KEYS'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'notebook_type'},{'id': '118', 'type': 'concatenated_string', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"\'><img "'},{'id': '120', 'type': 'string', 'children': [], 'value': '"src=\'../../images/icons/"'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'notebook_type'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'string', 'children': [], 'value': '".png\' width=\'15%\'>\\n\\t\\t</td>"'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '135'], 'value': '+'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133', '134'], 'value': '+'},{'id': '132', 'type': 'string', 'children': [], 'value': '"\\n\\t\\t<td width=\'60%\' class=\'center_cell open_cell_light\'>"'},{'id': '133', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'notebook_title'},{'id': '135', 'type': 'string', 'children': [], 'value': '"\\n\\t\\t</td>"'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '153'], 'value': '+'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '152'], 'value': '+'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '151'], 'value': '+'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '+'},{'id': '143', 'type': 'concatenated_string', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': '"\\n\\t\\t<td width=\'20%\' class=\'center_cell\'>\\n\\t\\t\\t<a href=\'"'},{'id': '145', 'type': 'string', 'children': [], 'value': '"../"'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'notebook_type'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'notebook_name'},{'id': '153', 'type': 'string', 'children': [], 'value': '"\'><div class=\'file_icon\'></div></a>\\n\\t\\t</td>\\n\\t</tr>"'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'},{'id': '157', 'type': 'string', 'children': [], 'value': '"</table>"'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '165']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'notebook_object'},{'id': '163', 'type': 'string', 'children': [], 'value': '"cells"'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nb'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'v4'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'new_markdown_cell'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'markdown_cell'}
def _generate_notebook_by_tag_body(notebook_object, dict_by_tag): tag_keys = list(dict_by_tag.keys()) tag_keys.sort() for tag in tag_keys: if tag.lower() not in SIGNAL_TYPE_LIST: markdown_cell = group_tag_code.TAG_TABLE_HEADER markdown_cell = markdown_cell.replace("Tag i", tag) for notebook_file in dict_by_tag[tag]: split_path = notebook_file.split("\\") notebook_type = split_path[-2] notebook_name = split_path[-1].split("&")[0] notebook_title = split_path[-1].split("&")[1] markdown_cell += "\t<tr>\n\t\t<td width='20%' class='header_image_color_" + \ str(NOTEBOOK_KEYS[notebook_type]) + "'><img " \ "src='../../images/icons/" + notebook_type.title() +\ ".png' width='15%'>\n\t\t</td>" markdown_cell += "\n\t\t<td width='60%' class='center_cell open_cell_light'>" + \ notebook_title + "\n\t\t</td>" markdown_cell += "\n\t\t<td width='20%' class='center_cell'>\n\t\t\t<a href='" \ "../" + notebook_type.title() + "/" + notebook_name + \ "'><div class='file_icon'></div></a>\n\t\t</td>\n\t</tr>" markdown_cell += "</table>" notebook_object["cells"].append(nb.v4.new_markdown_cell(markdown_cell))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_preprocess_params'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '6', 'type': 'block', 'children': ['7', '248']},{'id': '7', 'type': 'for_statement', 'children': ['8', '11', '16']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '34', '46']},{'id': '17', 'type': 'if_statement', 'children': ['18', '28']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '25'], 'value': 'and'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'is_the_primary_key'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_prevent_primary_key_initialization_'},{'id': '28', 'type': 'block', 'children': ['29', '33']},{'id': '29', 'type': 'delete_statement', 'children': ['30']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '33', 'type': 'continue_statement', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '37', 'type': 'string', 'children': [], 'value': '""'},{'id': '38', 'type': 'block', 'children': ['39', '45']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'continue_statement', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '61']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '56'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '50', 'type': 'attribute', 'children': ['51', '55']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'class_mapper'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'relationships'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'not'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_no_overwrite_'},{'id': '61', 'type': 'block', 'children': ['62', '73']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '65', 'type': 'subscript', 'children': ['66', '72']},{'id': '66', 'type': 'attribute', 'children': ['67', '71']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'class_mapper'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'relationships'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '73', 'type': 'if_statement', 'children': ['74', '77', '208']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'uselist'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '84', '128']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'if_statement', 'children': ['86', '97']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '88', 'type': 'generator_expression', 'children': ['89', '94']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '97', 'type': 'block', 'children': ['98', '107']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mapped_rel_class'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'update_or_new_all'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'list_of_kwargs'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '122', 'type': 'list', 'children': ['123'], 'value': '[rel_cls.primary_key_name()]'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'primary_key_name'},{'id': '127', 'type': 'argument_list', 'children': []},{'id': '128', 'type': 'elif_clause', 'children': ['129', '134']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '134', 'type': 'block', 'children': ['135', '144', '156', '177']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mapped_rel_class'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'mapping_col'},{'id': '147', 'type': 'attribute', 'children': ['148', '155']},{'id': '148', 'type': 'attribute', 'children': ['149', '154']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'collection_class'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'list_of_kwargs'},{'id': '159', 'type': 'list_comprehension', 'children': ['160', '168']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '164', 'type': 'dictionary', 'children': ['165']},{'id': '165', 'type': 'pair', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mapping_col'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '168', 'type': 'for_in_clause', 'children': ['169', '172']},{'id': '169', 'type': 'pattern_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '182', 'type': 'dictionary_comprehension', 'children': ['183', '190']},{'id': '183', 'type': 'pair', 'children': ['184', '189']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'mapping_col'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '190', 'type': 'for_in_clause', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'update_or_new_all'},{'id': '196', 'type': 'argument_list', 'children': ['197', '200']},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'list_of_kwargs'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'list_of_kwargs'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '202', 'type': 'list', 'children': ['203'], 'value': '[rel_cls.primary_key_name()]'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'primary_key_name'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'elif_clause', 'children': ['209', '214']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '214', 'type': 'block', 'children': ['215', '224']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'mapped_rel_class'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'update_or_new'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'dictionary_splat', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '239', 'type': 'dictionary', 'children': ['240']},{'id': '240', 'type': 'pair', 'children': ['241', '242']},{'id': '241', 'type': 'string', 'children': [], 'value': "'keys'"},{'id': '242', 'type': 'list', 'children': ['243'], 'value': '[rel_cls.primary_key_name()]'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'rel_cls'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'primary_key_name'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'return_statement', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def _preprocess_params(cls, kwargs): for attr, val in kwargs.items(): if cls.is_the_primary_key(attr) and cls._prevent_primary_key_initialization_: del kwargs[attr] continue if val == "": kwargs[attr] = None continue if attr in class_mapper(cls).relationships and attr not in cls._no_overwrite_: rel = class_mapper(cls).relationships[attr] if rel.uselist: if isinstance(val, list): if all(isinstance(v, dict) for v in val): rel_cls = cls.mapped_rel_class(attr) kwargs[attr] = rel_cls.update_or_new_all( list_of_kwargs=val, keys=[rel_cls.primary_key_name()]) elif isinstance(val, dict): rel_cls = cls.mapped_rel_class(attr) mapping_col = rel.collection_class().keyfunc.name list_of_kwargs = [merge(v, {mapping_col: k}) for k, v in val.items()] kwargs[attr] = {getattr(obj, mapping_col): obj for obj in rel_cls.update_or_new_all( list_of_kwargs=list_of_kwargs, keys=[rel_cls.primary_key_name()])} elif isinstance(val, dict): rel_cls = cls.mapped_rel_class(attr) kwargs[attr] = rel_cls.update_or_new( **merge(val, {'keys': [rel_cls.primary_key_name()]})) return kwargs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_all'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'check_type'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '37', '70']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'check_type'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '27']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'%s is not of type %s'"},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41', '59']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'add_all'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'list_comprehension', 'children': ['51', '52', '55']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '55', 'type': 'if_clause', 'children': ['56']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'add_all'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '70', 'type': 'try_statement', 'children': ['71', '85']},{'id': '71', 'type': 'block', 'children': ['72', '83']},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '85', 'type': 'except_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87', '95']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'rollback'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'raise_statement', 'children': []}
def add_all(cls, models, commit=True, check_type=False): if check_type: for model in models: if not isinstance(model, cls): raise ValueError('%s is not of type %s' (model, cls)) if None in models: cls.session.add_all([m for m in models if m is not None]) else: cls.session.add_all(models) try: if commit: cls.session.commit() return models except: cls.session.rollback() raise
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'peakdelta'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '33', '40', '58', '72', '84', '93', '101', '105', '216']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'maxtab'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mintab'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '40', 'type': 'if_statement', 'children': ['41', '50']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '46'], 'value': '!='},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'Input vectors v and x must have same length'"},{'id': '58', 'type': 'if_statement', 'children': ['59', '64']},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isscalar'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'Input argument delta must be a scalar'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '<='},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'Input argument delta must be positive'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'pattern_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '89', 'type': 'expression_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'Inf'},{'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Inf'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mnpos'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mxpos'},{'id': '98', 'type': 'expression_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'NaN'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'NaN'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'lookformax'},{'id': '104', 'type': 'True', 'children': []},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '114']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '114', 'type': 'block', 'children': ['115', '121', '136', '151']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '>'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '125', 'type': 'block', 'children': ['126', '130']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mxpos'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': '<'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '140', 'type': 'block', 'children': ['141', '145']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mnpos'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '151', 'type': 'if_statement', 'children': ['152', '153', '184']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'lookformax'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '<'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '-'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '160', 'type': 'block', 'children': ['161', '170', '174', '180']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'maxtab'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'tuple', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'mxpos'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'mnpos'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lookformax'},{'id': '183', 'type': 'False', 'children': []},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'if_statement', 'children': ['187', '192']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '>'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '192', 'type': 'block', 'children': ['193', '202', '206', '212']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'mintab'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'tuple', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'mnpos'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mn'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'mxpos'},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'lookformax'},{'id': '215', 'type': 'True', 'children': []},{'id': '216', 'type': 'return_statement', 'children': ['217']},{'id': '217', 'type': 'expression_list', 'children': ['218', '222']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'maxtab'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'mintab'}
def peakdelta(v, delta, x=None): maxtab = [] mintab = [] if x is None: x = arange(len(v)) v = asarray(v) if len(v) != len(x): sys.exit('Input vectors v and x must have same length') if not isscalar(delta): sys.exit('Input argument delta must be a scalar') if delta <= 0: sys.exit('Input argument delta must be positive') mn, mx = Inf, -Inf mnpos, mxpos = NaN, NaN lookformax = True for i in arange(len(v)): this = v[i] if this > mx: mx = this mxpos = x[i] if this < mn: mn = this mnpos = x[i] if lookformax: if this < mx - delta: maxtab.append((mxpos, mx)) mn = this mnpos = x[i] lookformax = False else: if this > mn + delta: mintab.append((mnpos, mn)) mx = this mxpos = x[i] lookformax = True return array(maxtab), array(mintab)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_datetime'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '5', 'type': 'block', 'children': ['6', '13', '69', '82', '91']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']},{'id': '14', 'type': 'function_name', 'children': [], 'value': '_get_fixed_timezone'},{'id': '15', 'type': 'parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '17', 'type': 'block', 'children': ['18', '33', '42', '55', '61']},{'id': '18', 'type': 'if_statement', 'children': ['19', '24']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '32'], 'value': '//'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '32', 'type': 'integer', 'children': [], 'value': '60'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '36', 'type': 'conditional_expression', 'children': ['37', '38', '41'], 'value': 'if'},{'id': '37', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'hhmm'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '%'},{'id': '46', 'type': 'string', 'children': [], 'value': "'%02d%02d'"},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '49', 'type': 'argument_list', 'children': ['50', '54']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '54', 'type': 'integer', 'children': [], 'value': '60'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'hhmm'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'FixedOffset'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'DATETIME_RE'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'concatenated_string', 'children': ['78', '79', '80', '81']},{'id': '78', 'type': 'string', 'children': [], 'value': "r'(?P<year>\\d{4})-(?P<month>\\d{1,2})-(?P<day>\\d{1,2})'"},{'id': '79', 'type': 'string', 'children': [], 'value': "r'[T ](?P<hour>\\d{1,2}):(?P<minute>\\d{1,2})'"},{'id': '80', 'type': 'string', 'children': [], 'value': "r'(?::(?P<second>\\d{1,2})(?:\\.(?P<microsecond>\\d{1,6})\\d{0,6})?)?'"},{'id': '81', 'type': 'string', 'children': [], 'value': "r'(?P<tzinfo>Z|[+-]\\d{2}(?::?\\d{2})?)?$'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'DATETIME_RE'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '93', 'type': 'block', 'children': ['94', '102', '121', '130', '201', '225', '231']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'groupdict'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '105', 'type': 'string', 'children': [], 'value': "'microsecond'"},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '111', 'type': 'string', 'children': [], 'value': "'microsecond'"},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '116', 'type': 'string', 'children': [], 'value': "'microsecond'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'integer', 'children': [], 'value': '6'},{'id': '120', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'tzinfo'"},{'id': '130', 'type': 'if_statement', 'children': ['131', '134', '141']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '=='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '133', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'UTC'},{'id': '141', 'type': 'elif_clause', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'block', 'children': ['146', '166', '182', '194']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'offset_mins'},{'id': '149', 'type': 'conditional_expression', 'children': ['150', '159', '165'], 'value': 'if'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '155', 'type': 'slice', 'children': ['156', '158']},{'id': '156', 'type': 'unary_operator', 'children': ['157'], 'value': '-'},{'id': '157', 'type': 'integer', 'children': [], 'value': '2'},{'id': '158', 'type': 'colon', 'children': []},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': '>'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '164', 'type': 'integer', 'children': [], 'value': '3'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '181'], 'value': '+'},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '*'},{'id': '171', 'type': 'integer', 'children': [], 'value': '60'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '177', 'type': 'slice', 'children': ['178', '179', '180']},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'colon', 'children': []},{'id': '180', 'type': 'integer', 'children': [], 'value': '3'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'offset_mins'},{'id': '182', 'type': 'if_statement', 'children': ['183', '188']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': '=='},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '192', 'type': 'unary_operator', 'children': ['193'], 'value': '-'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_get_fixed_timezone'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '204', 'type': 'dictionary_comprehension', 'children': ['205', '211', '221']},{'id': '205', 'type': 'pair', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '211', 'type': 'for_in_clause', 'children': ['212', '215']},{'id': '212', 'type': 'pattern_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '221', 'type': 'if_clause', 'children': ['222']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '224', 'type': 'None', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '230']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '229', 'type': 'string', 'children': [], 'value': "'tzinfo'"},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '231', 'type': 'return_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'dictionary_splat', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'kw'}
def parse_datetime(value): if value is None: return None def _get_fixed_timezone(offset): if isinstance(offset, timedelta): offset = offset.seconds // 60 sign = '-' if offset < 0 else '+' hhmm = '%02d%02d' % divmod(abs(offset), 60) name = sign + hhmm return pytz.FixedOffset(offset, name) DATETIME_RE = re.compile( r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})' r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$' ) match = DATETIME_RE.match(value) if match: kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') tzinfo = kw.pop('tzinfo') if tzinfo == 'Z': tzinfo = pytz.UTC elif tzinfo is not None: offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0 offset = 60 * int(tzinfo[1:3]) + offset_mins if tzinfo[0] == '-': offset = -offset tzinfo = _get_fixed_timezone(offset) kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} kw['tzinfo'] = tzinfo return datetime(**kw)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_property_grid_widget'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_height'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'custom_title'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'show_headers'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'show_columns'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '23', '82', '92', '102', '108', '131', '174', '183', '226', '232', '238', '279']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'max_height'},{'id': '23', 'type': 'if_statement', 'children': ['24', '29', '36', '65']},{'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': 'part_instance'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Part'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'part_instance_id'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '36', 'type': 'elif_clause', 'children': ['37', '47']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '43'], 'value': 'and'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'is_uuid'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'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': 'part_instance_id'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'part_instance_id'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'raise_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'concatenated_string', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': '"When using the add_property_grid_widget, part_instance must be a "'},{'id': '75', 'type': 'string', 'children': [], 'value': '"Part or Part id. Type is: {}"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '82', 'type': 'if_statement', 'children': ['83', '85']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'show_columns'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'show_columns'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'possible_columns'},{'id': '95', 'type': 'list', 'children': ['96', '99'], 'value': '[ShowColumnTypes.DESCRIPTION, ShowColumnTypes.UNIT]'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ShowColumnTypes'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'DESCRIPTION'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ShowColumnTypes'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'UNIT'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'display_columns'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'possible_column'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'possible_columns'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '123']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'possible_column'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'show_columns'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'display_columns'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'possible_column'},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'display_columns'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'possible_column'},{'id': '130', 'type': 'False', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '134', 'type': 'dictionary', 'children': ['135', '140', '145', '161', '165']},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '"xtype"'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ComponentXType'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'PROPERTYGRID'},{'id': '140', 'type': 'pair', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"category"'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'INSTANCE'},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': '"filter"'},{'id': '147', 'type': 'dictionary', 'children': ['148', '158']},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': '"activity_id"'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '158', 'type': 'pair', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': '"part"'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'part_instance_id'},{'id': '161', 'type': 'pair', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': '"hideHeaders"'},{'id': '163', 'type': 'not_operator', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'show_headers'},{'id': '165', 'type': 'pair', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"viewModel"'},{'id': '167', 'type': 'dictionary', 'children': ['168']},{'id': '168', 'type': 'pair', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': '"data"'},{'id': '170', 'type': 'dictionary', 'children': ['171']},{'id': '171', 'type': 'pair', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': '"displayColumns"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'display_columns'},{'id': '174', 'type': 'if_statement', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '181', 'type': 'string', 'children': [], 'value': "'height'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '183', 'type': 'if_statement', 'children': ['184', '187', '198', '213']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'is'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'custom_title'},{'id': '186', 'type': 'False', 'children': []},{'id': '187', 'type': 'block', 'children': ['188', '192']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'show_title_value'},{'id': '191', 'type': 'string', 'children': [], 'value': '"Default"'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '198', 'type': 'elif_clause', 'children': ['199', '202']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'custom_title'},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'block', 'children': ['203', '207']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'show_title_value'},{'id': '206', 'type': 'string', 'children': [], 'value': '"No title"'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'else_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215', '219']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'show_title_value'},{'id': '218', 'type': 'string', 'children': [], 'value': '"Custom title"'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'custom_title'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '230', 'type': 'string', 'children': [], 'value': '"title"'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '236', 'type': 'string', 'children': [], 'value': '"showTitleValue"'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'show_title_value'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '241', 'type': 'dictionary', 'children': ['242', '252', '258', '261', '264', '267', '270', '276']},{'id': '242', 'type': 'pair', 'children': ['243', '244']},{'id': '243', 'type': 'string', 'children': [], 'value': '"activityId"'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '252', 'type': 'pair', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': '"customHeight"'},{'id': '254', 'type': 'conditional_expression', 'children': ['255', '256', '257'], 'value': 'if'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '257', 'type': 'None', 'children': []},{'id': '258', 'type': 'pair', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': '"customTitle"'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': '"partInstanceId"'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'part_instance_id'},{'id': '264', 'type': 'pair', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': '"showColumns"'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'show_columns'},{'id': '267', 'type': 'pair', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': '"showHeaders"'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'show_headers'},{'id': '270', 'type': 'pair', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': '"showHeightValue"'},{'id': '272', 'type': 'conditional_expression', 'children': ['273', '274', '275'], 'value': 'if'},{'id': '273', 'type': 'string', 'children': [], 'value': '"Set height"'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '275', 'type': 'string', 'children': [], 'value': '"Automatic height"'},{'id': '276', 'type': 'pair', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': '"showTitleValue"'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'show_title_value'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_add_widget'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '287', 'type': 'argument_list', 'children': ['288', '291', '294']},{'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'WidgetNames'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'PROPERTYGRIDWIDGET'}
def add_property_grid_widget(self, part_instance, max_height=None, custom_title=False, show_headers=True, show_columns=None): height = max_height if isinstance(part_instance, Part): part_instance_id = part_instance.id elif isinstance(part_instance, text_type) and is_uuid(part_instance): part_instance_id = part_instance part_instance = self._client.part(id=part_instance_id) else: raise IllegalArgumentError("When using the add_property_grid_widget, part_instance must be a " "Part or Part id. Type is: {}".format(type(part_instance))) if not show_columns: show_columns = list() possible_columns = [ShowColumnTypes.DESCRIPTION, ShowColumnTypes.UNIT] display_columns = dict() for possible_column in possible_columns: if possible_column in show_columns: display_columns[possible_column] = True else: display_columns[possible_column] = False config = { "xtype": ComponentXType.PROPERTYGRID, "category": Category.INSTANCE, "filter": { "activity_id": str(self.activity.id), "part": part_instance_id }, "hideHeaders": not show_headers, "viewModel": { "data": { "displayColumns": display_columns } }, } if height: config['height'] = height if custom_title is False: show_title_value = "Default" title = part_instance.name elif custom_title is None: show_title_value = "No title" title = str() else: show_title_value = "Custom title" title = str(custom_title) config["title"] = title config["showTitleValue"] = show_title_value meta = { "activityId": str(self.activity.id), "customHeight": height if height else None, "customTitle": title, "partInstanceId": part_instance_id, "showColumns": show_columns, "showHeaders": show_headers, "showHeightValue": "Set height" if height else "Automatic height", "showTitleValue": show_title_value } self._add_widget(dict(config=config, meta=meta, name=WidgetNames.PROPERTYGRIDWIDGET))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_data_for_format'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '216']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'free_size_start'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '20', '26']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17', '18', '19']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'literal_text'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'conversion'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '26', 'type': 'block', 'children': ['27', '34', '43', '66']},{'id': '27', 'type': 'if_statement', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'literal_text'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'free_size_start'},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '37']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '37', 'type': 'block', 'children': ['38', '42']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'free_size_start'},{'id': '41', 'type': 'False', 'children': []},{'id': '42', 'type': 'continue_statement', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '54']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '51'], 'value': 'or'},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '48'], 'value': 'or'},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '50', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '53', 'type': 'string', 'children': [], 'value': '"d"'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'free_size_start'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'free_size_start'},{'id': '65', 'type': 'True', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '72', '114', '157']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '69'], 'value': 'and'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'in'},{'id': '70', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '72', 'type': 'block', 'children': ['73', '83', '108']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '86', 'type': 'subscript', 'children': ['87', '107']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '89', 'type': 'argument_list', 'children': ['90', '95']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '94'], 'value': '+'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'},{'id': '92', 'type': 'string', 'children': [], 'value': '"{t:"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '94', 'type': 'string', 'children': [], 'value': '"}"'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'compose'},{'id': '97', 'type': 'argument_list', 'children': ['98', '103']},{'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '+'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'string', 'children': [], 'value': '"{t:"'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '102', 'type': 'string', 'children': [], 'value': '"}"'},{'id': '103', 'type': 'dictionary', 'children': ['104']},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'t'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '107', 'type': 'string', 'children': [], 'value': "'t'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '114', 'type': 'elif_clause', 'children': ['115', '120']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '117'], 'value': 'and'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'in'},{'id': '118', 'type': 'string', 'children': [], 'value': "'d'"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '120', 'type': 'block', 'children': ['121', '140']},{'id': '121', 'type': 'if_statement', 'children': ['122', '128', '136']},{'id': '122', 'type': 'not_operator', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'isalpha'},{'id': '127', 'type': 'argument_list', 'children': []},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_get_number_from_fmt'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '153'], 'value': '%'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'integer', 'children': [], 'value': '99999999999999999'},{'id': '153', 'type': '()', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '**'},{'id': '155', 'type': 'integer', 'children': [], 'value': '10'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159', '188', '192', '210']},{'id': '159', 'type': 'if_statement', 'children': ['160', '163', '168', '182']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'is'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '162', 'type': 'None', 'children': []},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '167', 'type': 'integer', 'children': [], 'value': '4'},{'id': '168', 'type': 'elif_clause', 'children': ['169', '174']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'isalnum'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_get_number_from_fmt'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'format_spec'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '187', 'type': 'integer', 'children': [], 'value': '4'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'randstri'},{'id': '191', 'type': 'string', 'children': [], 'value': "''"},{'id': '192', 'type': 'for_statement', 'children': ['193', '194', '198']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'augmented_assignment', 'children': ['201', '202'], 'value': '+='},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'randstri'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ascii_letters'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'randstri'},{'id': '216', 'type': 'return_statement', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'data'}
def _generate_data_for_format(fmt): data = {} free_size_start = False for literal_text, field_name, format_spec, conversion in formatter.parse(fmt): if literal_text: free_size_start = False if not field_name: free_size_start = False continue if not format_spec or format_spec == "s" or format_spec == "d": if free_size_start: return None else: free_size_start = True if format_spec and '%' in format_spec: t = dt.datetime.now() t = parse( "{t:" + format_spec + "}", compose("{t:" + format_spec + "}", {'t': t}))['t'] data[field_name] = t elif format_spec and 'd' in format_spec: if not format_spec.isalpha(): n = _get_number_from_fmt(format_spec) else: return None data[field_name] = random.randint(0, 99999999999999999) % (10 ** n) else: if format_spec is None: n = 4 elif format_spec.isalnum(): n = _get_number_from_fmt(format_spec) else: n = 4 randstri = '' for x in range(n): randstri += random.choice(string.ascii_letters) data[field_name] = randstri return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'relocate_model'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '46', '61', '69', '85', '100', '114', '120', '136', '358', '391']},{'id': '13', 'type': 'if_statement', 'children': ['14', '28']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'in'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_illegal_targets'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '24', 'type': 'set', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'concatenated_string', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '\'cannot relocate part "{}" under target parent "{}", because the target is part of \''},{'id': '37', 'type': 'string', 'children': [], 'value': "'its descendants'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '39', 'type': 'argument_list', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '46', 'type': 'if_statement', 'children': ['47', '49']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"CLONE - {}"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'part_desc'},{'id': '64', 'type': 'subscript', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '68', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'add_model'},{'id': '76', 'type': 'argument_list', 'children': ['77', '80']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'part_desc'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'edit'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'part_desc'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'dictionary', 'children': ['109']},{'id': '109', 'type': 'pair', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'list_of_properties_sorted_by_order'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'list_of_properties_sorted_by_order'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'lambda', 'children': ['129', '131']},{'id': '129', 'type': 'lambda_parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'subscript', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '135', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'list_of_properties_sorted_by_order'},{'id': '139', 'type': 'block', 'children': ['140', '151', '162', '173', '184', '348']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': "'property_type'"},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': "'unit'"},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '184', 'type': 'if_statement', 'children': ['185', '190', '225', '316']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'REFERENCES_VALUE'},{'id': '190', 'type': 'block', 'children': ['191', '203']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'referenced_part_ids'},{'id': '194', 'type': 'list_comprehension', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'referenced_part'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '198', 'type': 'for_in_clause', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'referenced_part'},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'add_property'},{'id': '210', 'type': 'argument_list', 'children': ['211', '216', '219', '222']},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'referenced_part_ids'},{'id': '225', 'type': 'elif_clause', 'children': ['226', '231']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '=='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ATTACHMENT_VALUE'},{'id': '231', 'type': 'block', 'children': ['232', '251']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'add_property'},{'id': '239', 'type': 'argument_list', 'children': ['240', '245', '248']},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '251', 'type': 'if_statement', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '255', 'type': 'block', 'children': ['256', '272']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'attachment_name'},{'id': '259', 'type': 'subscript', 'children': ['260', '270']},{'id': '260', 'type': 'call', 'children': ['261', '268']},{'id': '261', 'type': 'attribute', 'children': ['262', '267']},{'id': '262', 'type': 'subscript', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '265', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '266', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '270', 'type': 'unary_operator', 'children': ['271'], 'value': '-'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'with_statement', 'children': ['273', '281']},{'id': '273', 'type': 'with_clause', 'children': ['274']},{'id': '274', 'type': 'with_item', 'children': ['275']},{'id': '275', 'type': 'as_pattern', 'children': ['276', '279']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'temp_chdir'},{'id': '278', 'type': 'argument_list', 'children': []},{'id': '279', 'type': 'as_pattern_target', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '281', 'type': 'block', 'children': ['282', '300', '309']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '291', 'type': 'argument_list', 'children': ['292', '299']},{'id': '292', 'type': 'boolean_operator', 'children': ['293', '294'], 'value': 'or'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'attachment_name'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'save_as'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'upload'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '316', 'type': 'else_clause', 'children': ['317']},{'id': '317', 'type': 'block', 'children': ['318']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'add_property'},{'id': '325', 'type': 'argument_list', 'children': ['326', '331', '334', '337', '342', '345']},{'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'prop_type'},{'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '342', 'type': 'keyword_argument', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '345', 'type': 'keyword_argument', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '357']},{'id': '350', 'type': 'subscript', 'children': ['351', '354']},{'id': '351', 'type': 'call', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '353', 'type': 'argument_list', 'children': []},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '358', 'type': 'if_statement', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '360', 'type': 'block', 'children': ['361', '367']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'populate_descendants'},{'id': '366', 'type': 'argument_list', 'children': []},{'id': '367', 'type': 'for_statement', 'children': ['368', '369', '372']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'sub_part'},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '371', 'type': 'identifier', 'children': [], 'value': '_cached_children'},{'id': '372', 'type': 'block', 'children': ['373']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'relocate_model'},{'id': '376', 'type': 'argument_list', 'children': ['377', '380', '383', '388']},{'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'sub_part'},{'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'},{'id': '383', 'type': 'keyword_argument', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'sub_part'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '391', 'type': 'return_statement', 'children': ['392']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'moved_part_model'}
def relocate_model(part, target_parent, name=None, include_children=True): if target_parent.id in get_illegal_targets(part, include={part.id}): raise IllegalArgumentError('cannot relocate part "{}" under target parent "{}", because the target is part of ' 'its descendants'.format(part.name, target_parent.name)) if not name: name = "CLONE - {}".format(part.name) part_desc = part._json_data['description'] moved_part_model = target_parent.add_model(name=name, multiplicity=part.multiplicity) if part_desc: moved_part_model.edit(description=str(part_desc)) get_mapping_dictionary().update({part.id: moved_part_model}) list_of_properties_sorted_by_order = part.properties list_of_properties_sorted_by_order.sort(key=lambda x: x._json_data['order']) for prop in list_of_properties_sorted_by_order: prop_type = prop._json_data.get('property_type') desc = prop._json_data.get('description') unit = prop._json_data.get('unit') options = prop._json_data.get('options') if prop_type == PropertyType.REFERENCES_VALUE: referenced_part_ids = [referenced_part.id for referenced_part in prop.value] moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type, default_value=referenced_part_ids) elif prop_type == PropertyType.ATTACHMENT_VALUE: moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type) if prop.value: attachment_name = prop._json_data['value'].split('/')[-1] with temp_chdir() as target_dir: full_path = os.path.join(target_dir or os.getcwd(), attachment_name) prop.save_as(filename=full_path) moved_prop.upload(full_path) else: moved_prop = moved_part_model.add_property(name=prop.name, description=desc, property_type=prop_type, default_value=prop.value, unit=unit, options=options) get_mapping_dictionary()[prop.id] = moved_prop if include_children: part.populate_descendants() for sub_part in part._cached_children: relocate_model(part=sub_part, target_parent=moved_part_model, name=sub_part.name, include_children=include_children) return moved_part_model
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'relocate_instance'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '28', '36', '44', '62', '71', '92']},{'id': '13', 'type': 'if_statement', 'children': ['14', '16']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': '"CLONE - {}"'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'target_parent_model'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'relocate_model'},{'id': '47', 'type': 'argument_list', 'children': ['48', '51', '54', '59']},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'target_parent_model'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '62', 'type': 'if_statement', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'populate_descendants'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'move_part_instance'},{'id': '76', 'type': 'argument_list', 'children': ['77', '80', '83', '86', '89']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'moved_instance'}
def relocate_instance(part, target_parent, name=None, include_children=True): if not name: name = "CLONE - {}".format(part.name) part_model = part.model() target_parent_model = target_parent.model() relocate_model(part=part_model, target_parent=target_parent_model, name=part_model.name, include_children=include_children) if include_children: part.populate_descendants() moved_instance = move_part_instance(part_instance=part, target_parent=target_parent, part_model=part_model, name=name, include_children=include_children) return moved_instance
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'move_part_instance'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '24', '34', '222', '256']},{'id': '14', 'type': 'if_statement', 'children': ['15', '17']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '34', 'type': 'if_statement', 'children': ['35', '42', '78', '183']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Multiplicity'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ONE'},{'id': '42', 'type': 'block', 'children': ['43', '58', '64']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '46', 'type': 'subscript', 'children': ['47', '57']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'map_property_instances'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'update_part_with_properties'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '86']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': '=='},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'Multiplicity'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ONE_MANY'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'if_statement', 'children': ['88', '95', '142']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': 'not'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_edited_one_many'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '111', '117', '131']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '99', 'type': 'subscript', 'children': ['100', '110']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'map_property_instances'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'update_part_with_properties'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get_edited_one_many'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144', '163', '169']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '151', 'type': 'argument_list', 'children': ['152', '157', '160']},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'suppress_kevents'},{'id': '162', 'type': 'True', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'map_property_instances'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'update_part_with_properties'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '183', 'type': 'else_clause', 'children': ['184']},{'id': '184', 'type': 'block', 'children': ['185', '202', '208']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '192', 'type': 'argument_list', 'children': ['193', '196', '199']},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'suppress_kevents'},{'id': '201', 'type': 'True', 'children': []},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'map_property_instances'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'update_part_with_properties'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215', '216']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '222', 'type': 'if_statement', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'sub_instance'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_cached_children'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'move_part_instance'},{'id': '234', 'type': 'argument_list', 'children': ['235', '238', '241', '248', '253']},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sub_instance'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'sub_instance'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'sub_instance'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '255', 'type': 'True', 'children': []},{'id': '256', 'type': 'return_statement', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'moved_instance'}
def move_part_instance(part_instance, target_parent, part_model, name=None, include_children=True): if not name: name = part_instance.name moved_model = get_mapping_dictionary()[part_model.id] if moved_model.multiplicity == Multiplicity.ONE: moved_instance = moved_model.instances(parent_id=target_parent.id)[0] map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) elif moved_model.multiplicity == Multiplicity.ONE_MANY: if target_parent.id not in get_edited_one_many(): moved_instance = moved_model.instances(parent_id=target_parent.id)[0] map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) get_edited_one_many().append(target_parent.id) else: moved_instance = target_parent.add(name=part_instance.name, model=moved_model, suppress_kevents=True) map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) else: moved_instance = target_parent.add(name=name, model=moved_model, suppress_kevents=True) map_property_instances(part_instance, moved_instance) moved_instance = update_part_with_properties(part_instance, moved_instance, name=str(name)) if include_children: for sub_instance in part_instance._cached_children: move_part_instance(part_instance=sub_instance, target_parent=moved_instance, part_model=sub_instance.model(), name=sub_instance.name, include_children=True) return moved_instance
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_part_with_properties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16', '180', '201']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'properties_id_dict'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '32', '116', '158']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '29'], 'value': '=='},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '28', 'type': 'string', 'children': [], 'value': "'property_type'"},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ATTACHMENT_VALUE'},{'id': '32', 'type': 'block', 'children': ['33', '43']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '43', 'type': 'if_statement', 'children': ['44', '47', '108']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '47', 'type': 'block', 'children': ['48', '64']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'attachment_name'},{'id': '51', 'type': 'subscript', 'children': ['52', '62']},{'id': '52', 'type': 'call', 'children': ['53', '60']},{'id': '53', 'type': 'attribute', 'children': ['54', '59']},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '58', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'with_statement', 'children': ['65', '73']},{'id': '65', 'type': 'with_clause', 'children': ['66']},{'id': '66', 'type': 'with_item', 'children': ['67']},{'id': '67', 'type': 'as_pattern', 'children': ['68', '71']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'temp_chdir'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'as_pattern_target', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '73', 'type': 'block', 'children': ['74', '92', '101']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'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': 'os'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '83', 'type': 'argument_list', 'children': ['84', '91']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'or'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'attachment_name'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'save_as'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'upload'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'moved_prop'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'elif_clause', 'children': ['117', '126']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '123'], 'value': '=='},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '122', 'type': 'string', 'children': [], 'value': "'property_type'"},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'REFERENCES_VALUE'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'if_statement', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '131', 'type': 'block', 'children': ['132', '142']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'moved_prop_instance'},{'id': '135', 'type': 'subscript', 'children': ['136', '139']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '149']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'properties_id_dict'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'moved_prop_instance'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '149', 'type': 'list_comprehension', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ref_part'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '153', 'type': 'for_in_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ref_part'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160', '170']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'moved_prop_instance'},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_mapping_dictionary'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'properties_id_dict'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'moved_prop_instance'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'prop_instance'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '185', 'type': 'argument_list', 'children': ['186', '192', '195', '198']},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'properties_id_dict'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '197', 'type': 'True', 'children': []},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'suppress_kevents'},{'id': '200', 'type': 'True', 'children': []},{'id': '201', 'type': 'return_statement', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'moved_instance'}
def update_part_with_properties(part_instance, moved_instance, name=None): properties_id_dict = dict() for prop_instance in part_instance.properties: if prop_instance._json_data['property_type'] == PropertyType.ATTACHMENT_VALUE: moved_prop = get_mapping_dictionary()[prop_instance.id] if prop_instance.value: attachment_name = prop_instance._json_data['value'].split('/')[-1] with temp_chdir() as target_dir: full_path = os.path.join(target_dir or os.getcwd(), attachment_name) prop_instance.save_as(filename=full_path) moved_prop.upload(full_path) else: moved_prop.clear() elif prop_instance._json_data['property_type'] == PropertyType.REFERENCES_VALUE: if prop_instance.value: moved_prop_instance = get_mapping_dictionary()[prop_instance.id] properties_id_dict[moved_prop_instance.id] = [ref_part.id for ref_part in prop_instance.value] else: moved_prop_instance = get_mapping_dictionary()[prop_instance.id] properties_id_dict[moved_prop_instance.id] = prop_instance.value moved_instance.update(name=str(name), update_dict=properties_id_dict, bulk=True, suppress_kevents=True) return moved_instance
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_checkup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'peaks'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ecg_integrated'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sample_rate'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '11', 'type': 'block', 'children': ['12', '22', '26', '171', '180']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'peaks_amp'},{'id': '15', 'type': 'list_comprehension', 'children': ['16', '19']},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ecg_integrated'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'peaks'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '30', '34']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'peaks'},{'id': '34', 'type': 'block', 'children': ['35', '41', '163']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'peaks_amp'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '60', '153']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '>'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '52']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_acceptpeak'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57', '58', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '80']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '72'], 'value': 'and'},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '68'], 'value': 'and'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '/'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '67', 'type': 'integer', 'children': [], 'value': '2'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': '>'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'peaks'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'block', 'children': ['81', '90', '105', '118']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mean_rr'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'last_qrs_ms'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '101'], 'value': '*'},{'id': '94', 'type': '()', 'children': ['95']},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '99', 'type': 'unary_operator', 'children': ['100'], 'value': '-'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '/'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sample_rate'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'last_qrs_to_next_peak'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '-'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'peaks'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '+'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '116', 'type': 'unary_operator', 'children': ['117'], 'value': '-'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'if_statement', 'children': ['119', '128', '143']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '>'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'last_qrs_ms'},{'id': '122', 'type': 'integer', 'children': [], 'value': '360'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'last_qrs_to_next_peak'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '*'},{'id': '126', 'type': 'float', 'children': [], 'value': '1.5'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'mean_rr'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '135']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_acceptpeak'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '141', '142']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rr_buffer'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_noisepeak'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '153', 'type': 'else_clause', 'children': ['154']},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_noisepeak'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'amp'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_buffer_update'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'npk1'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'spk1'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'definitive_peaks'}
def _checkup(peaks, ecg_integrated, sample_rate, rr_buffer, spk1, npk1, threshold): peaks_amp = [ecg_integrated[peak] for peak in peaks] definitive_peaks = [] for i, peak in enumerate(peaks): amp = peaks_amp[i] if amp > threshold: definitive_peaks, spk1, rr_buffer = _acceptpeak(peak, amp, definitive_peaks, spk1, rr_buffer) elif amp > threshold / 2 and list(definitive_peaks) and len(peaks) > i + 1: mean_rr = numpy.mean(rr_buffer) last_qrs_ms = (peak - definitive_peaks[-1]) * (1000 / sample_rate) last_qrs_to_next_peak = peaks[i+1] - definitive_peaks[-1] if last_qrs_ms > 360 and last_qrs_to_next_peak > 1.5 * mean_rr: definitive_peaks, spk1, rr_buffer = _acceptpeak(peak, amp, definitive_peaks, spk1, rr_buffer) else: npk1 = _noisepeak(amp, npk1) else: npk1 = _noisepeak(amp, npk1) threshold = _buffer_update(npk1, spk1) definitive_peaks = numpy.array(definitive_peaks) return definitive_peaks
{'id': '0', 'type': 'module', 'children': ['1', '175', '182', '197', '206', '213', '220', '237', '291', '305', '309', '317']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_napp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'meta_package'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15', '27', '31', '35', '40', '45', '50', '55', '60', '65', '70', '75', '80', '85', '101', '117', '126', '145', '155']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'templates_path'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '14'], 'value': '/'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'SKEL_PATH'},{'id': '14', 'type': 'string', 'children': [], 'value': "'napp-structure/username/napp'"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ui_templates_path'},{'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': 'os'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'templates_path'},{'id': '26', 'type': 'string', 'children': [], 'value': "'ui'"},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'--------------------------------------------------------------'"},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'Welcome to the bootstrap process of your NApp.'"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'--------------------------------------------------------------'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'In order to answer both the username and the napp name,'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'You must follow this naming rules:'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "' - name starts with a letter'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "' - name contains only letters, numbers or underscores'"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "' - at least three characters'"},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'--------------------------------------------------------------'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "''"},{'id': '85', 'type': 'while_statement', 'children': ['86', '93']},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'valid_name'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': "'Please, insert your NApps Server username: '"},{'id': '101', 'type': 'while_statement', 'children': ['102', '109']},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'valid_name'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'Please, insert your NApp name: '"},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'concatenated_string', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'Please, insert a brief description for your'"},{'id': '125', 'type': 'string', 'children': [], 'value': "'NApp [optional]: '"},{'id': '126', 'type': 'if_statement', 'children': ['127', '129']},{'id': '127', 'type': 'not_operator', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '129', 'type': 'block', 'children': ['130', '142']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '133', 'type': 'expression_list', 'children': ['134', '139']},{'id': '134', 'type': 'concatenated_string', 'children': ['135', '136', '138']},{'id': '135', 'type': 'string', 'children': [], 'value': "'\n context = {'"},{'id': '136', 'type': 'ERROR', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '138', 'type': 'string', 'children': [], 'value': "': username, '"},{'id': '139', 'type': 'ERROR', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'napp'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '142', 'type': 'ERROR', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'exist_ok'},{'id': '154', 'type': 'True', 'children': []},{'id': '155', 'type': 'with_statement', 'children': ['156', '174']},{'id': '156', 'type': 'with_clause', 'children': ['157']},{'id': '157', 'type': 'with_item', 'children': ['158']},{'id': '158', 'type': 'as_pattern', 'children': ['159', '172']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '161', 'type': 'argument_list', 'children': ['162', '171']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '170', 'type': 'string', 'children': [], 'value': "'__init__.py'"},{'id': '171', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '172', 'type': 'as_pattern_target', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'init_file'},{'id': '174', 'type': 'block', 'children': [], 'value': ''},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'init_file'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': 'f\'"\''},{'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': 'os'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'templates_path'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'string', 'children': [], 'value': "'ui'"},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'openapi.yml.template'"},{'id': '220', 'type': 'if_statement', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'meta_package'},{'id': '222', 'type': 'block', 'children': ['223', '230']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'string', 'children': [], 'value': "'main.py.template'"},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'string', 'children': [], 'value': "'settings.py.template'"},{'id': '237', 'type': 'for_statement', 'children': ['238', '239', '240']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'templates'},{'id': '240', 'type': 'block', 'children': ['241', '261']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '244', 'type': 'call', 'children': ['245', '250']},{'id': '245', 'type': 'attribute', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '253', 'type': 'subscript', 'children': ['254', '260']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'string', 'children': [], 'value': "'.template'"},{'id': '260', 'type': 'integer', 'children': [], 'value': '0'},{'id': '261', 'type': 'with_statement', 'children': ['262', '272']},{'id': '262', 'type': 'with_clause', 'children': ['263']},{'id': '263', 'type': 'with_item', 'children': ['264']},{'id': '264', 'type': 'as_pattern', 'children': ['265', '270']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '269', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '270', 'type': 'as_pattern_target', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '272', 'type': 'block', 'children': ['273', '284']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'render_template'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282', '283']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'templates_path'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '291', 'type': 'if_statement', 'children': ['292', '294']},{'id': '292', 'type': 'not_operator', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'meta_package'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'NAppsManager'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'create_ui_structure'},{'id': '300', 'type': 'argument_list', 'children': ['301', '302', '303', '304']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'napp_name'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'ui_templates_path'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '308', 'type': 'argument_list', 'children': []},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'concatenated_string', 'children': ['314', '315', '316']},{'id': '314', 'type': 'string', 'children': [], 'value': "f'Congratulations! Your NApp has been bootstrapped!\\nNow you '"},{'id': '315', 'type': 'string', 'children': [], 'value': "'can go to the directory {username}/{napp_name} and begin to '"},{'id': '316', 'type': 'string', 'children': [], 'value': "'code your NApp.'"},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'string', 'children': [], 'value': "'Have fun!'"}
def create_napp(cls, meta_package=False): templates_path = SKEL_PATH / 'napp-structure/username/napp' ui_templates_path = os.path.join(templates_path, 'ui') username = None napp_name = None print('--------------------------------------------------------------') print('Welcome to the bootstrap process of your NApp.') print('--------------------------------------------------------------') print('In order to answer both the username and the napp name,') print('You must follow this naming rules:') print(' - name starts with a letter') print(' - name contains only letters, numbers or underscores') print(' - at least three characters') print('--------------------------------------------------------------') print('') while not cls.valid_name(username): username = input('Please, insert your NApps Server username: ') while not cls.valid_name(napp_name): napp_name = input('Please, insert your NApp name: ') description = input('Please, insert a brief description for your' 'NApp [optional]: ') if not description: description = ' context = {'username': username, 'napp': napp_name, 'description': description} os.makedirs(username, exist_ok=True) with open(os.path.join(username, '__init__.py'), 'w') as init_file: init_file.write(f'"') os.makedirs(os.path.join(username, napp_name)) templates = os.listdir(templates_path) templates.remove('ui') templates.remove('openapi.yml.template') if meta_package: templates.remove('main.py.template') templates.remove('settings.py.template') for tmp in templates: fname = os.path.join(username, napp_name, tmp.rsplit('.template')[0]) with open(fname, 'w') as file: content = cls.render_template(templates_path, tmp, context) file.write(content) if not meta_package: NAppsManager.create_ui_structure(username, napp_name, ui_templates_path, context) print() print(f'Congratulations! Your NApp has been bootstrapped!\nNow you ' 'can go to the directory {username}/{napp_name} and begin to ' 'code your NApp.') print('Have fun!')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_app_version'},{'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': 'app'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '94', '103', '114']},{'id': '18', 'type': 'if_statement', 'children': ['19', '30', '87']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '22'], 'value': 'or'},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '25'], 'value': 'and'},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': '()', 'children': ['27']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '29'], 'value': 'and'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '30', 'type': 'block', 'children': ['31', '59']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '34', 'type': 'list_comprehension', 'children': ['35', '36', '41']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'app_versions'},{'id': '41', 'type': 'if_clause', 'children': ['42']},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '51'], 'value': 'or'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '50'], 'value': '=='},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'app'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '=='},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '59', 'type': 'if_statement', 'children': ['60', '69', '75']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '63'], 'value': 'and'},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': '"Could not find the app or label provided"'},{'id': '75', 'type': 'elif_clause', 'children': ['76', '84']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '79'], 'value': 'and'},{'id': '77', 'type': 'not_operator', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"Please provide either app or label"'},{'id': '94', 'type': 'if_statement', 'children': ['95', '97']},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'raise_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': '"Please provide semantic version string including operand eg: `>=1.0.0`"'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '106', 'type': 'call', 'children': ['107', '112']},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '114', 'type': 'if_statement', 'children': ['115', '120', '132']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '119'], 'value': 'and'},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '118'], 'value': 'and'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '120', 'type': 'block', 'children': ['121', '124']},{'id': '121', 'type': 'import_statement', 'children': ['122']},{'id': '122', 'type': 'dotted_name', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'semver'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'semver'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '132', 'type': 'elif_clause', 'children': ['133', '135']},{'id': '133', 'type': 'not_operator', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'if_statement', 'children': ['137', '142', '145']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'raise_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': '"No version found on the app \'{}\'"'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'target_app'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': "'app'"}
def match_app_version(self, app=None, label=None, version=None, default=False): if not app or not label and not (app and label): target_app = [a for a in self.app_versions if a.get('app') == app or a.get('label') == label] if not target_app and not isinstance(default, bool): raise NotFoundError("Could not find the app or label provided") elif not target_app and isinstance(default, bool): return default else: raise IllegalArgumentError("Please provide either app or label") if not version: raise IllegalArgumentError("Please provide semantic version string including operand eg: `>=1.0.0`") app_version = target_app[0].get('version') if target_app and app_version and version: import semver return semver.match(app_version, version) elif not app_version: if isinstance(default, bool): return default else: raise NotFoundError("No version found on the app '{}'".format(target_app[0].get('app')))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'activities'},{'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': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '30', '55', '66', '84', '108', '116']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '20', 'type': 'dictionary', 'children': ['21', '24', '27']},{'id': '21', 'type': 'pair', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'scope'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '30', 'type': 'if_statement', 'children': ['31', '45']},{'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': 'match_app_version'},{'id': '35', 'type': 'argument_list', 'children': ['36', '39', '42']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '38', 'type': 'string', 'children': [], 'value': "'wim'"},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '41', 'type': 'string', 'children': [], 'value': "'>=2.0.0'"},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'API_EXTRA_PARAMS'},{'id': '54', 'type': 'string', 'children': [], 'value': "'activity'"},{'id': '55', 'type': 'if_statement', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'request_params'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'dictionary_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '81']},{'id': '74', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'activities'"},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '84', 'type': 'if_statement', 'children': ['85', '94']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '!='},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'raise_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': '"Could not retrieve activities. Server responded with {}"'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '131', '146']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'match_app_version'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125', '128']},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '124', 'type': 'string', 'children': [], 'value': "'wim'"},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '127', 'type': 'string', 'children': [], 'value': "'<2.0.0'"},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'list_comprehension', 'children': ['134', '141']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'Activity'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '145', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'list_comprehension', 'children': ['150', '157']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Activity2'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '161', 'type': 'string', 'children': [], 'value': "'results'"}
def activities(self, name=None, pk=None, scope=None, **kwargs): request_params = { 'id': pk, 'name': name, 'scope': scope } if self.match_app_version(label='wim', version='>=2.0.0', default=False): request_params.update(API_EXTRA_PARAMS['activity']) if kwargs: request_params.update(**kwargs) response = self._request('GET', self._build_url('activities'), params=request_params) if response.status_code != requests.codes.ok: raise NotFoundError("Could not retrieve activities. Server responded with {}".format(str(response))) data = response.json() if self.match_app_version(label='wim', version='<2.0.0', default=True): return [Activity(a, client=self) for a in data['results']] else: return [Activity2(a, client=self) for a in data['results']]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '19', '22', '25', '28', '31', '34']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'INSTANCE'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '33', 'type': 'integer', 'children': [], 'value': '100'},{'id': '34', 'type': 'dictionary_splat_pattern', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '36', 'type': 'block', 'children': ['37', '48', '81', '92', '110', '126', '134', '140', '195']},{'id': '37', 'type': 'if_statement', 'children': ['38', '43']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '40'], 'value': 'and'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '<'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '51', 'type': 'dictionary', 'children': ['52', '55', '58', '66', '69', '72', '75', '78']},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'model'"},{'id': '60', 'type': 'conditional_expression', 'children': ['61', '64', '65'], 'value': 'if'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'pair', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'category'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '69', 'type': 'pair', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'bucket'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'activity_id'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '81', 'type': 'if_statement', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'dictionary_splat', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '107']},{'id': '100', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '110', 'type': 'if_statement', 'children': ['111', '120']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '!='},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': '"Could not retrieve parts"'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'part_results'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '139', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '140', 'type': 'if_statement', 'children': ['141', '149']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '143'], 'value': 'and'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': "'next'"},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'while_statement', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '153', 'type': 'string', 'children': [], 'value': "'next'"},{'id': '154', 'type': 'block', 'children': ['155', '166', '178', '186']},{'id': '155', 'type': 'if_statement', 'children': ['156', '164']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '158'], 'value': 'and'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '163'], 'value': '>='},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'part_results'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'break_statement', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': '_request'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'string', 'children': [], 'value': "'next'"},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'part_results'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '194', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'PartSet'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'generator_expression', 'children': ['200', '207']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'Part'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'for_in_clause', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'part_results'}
def parts(self, name=None, pk=None, model=None, category=Category.INSTANCE, bucket=None, parent=None, activity=None, limit=None, batch=100, **kwargs): if limit and limit < batch: batch = limit request_params = { 'id': pk, 'name': name, 'model': model.id if model else None, 'category': category, 'bucket': bucket, 'parent': parent, 'activity_id': activity, 'limit': batch } if kwargs: request_params.update(**kwargs) response = self._request('GET', self._build_url('parts'), params=request_params) if response.status_code != requests.codes.ok: raise NotFoundError("Could not retrieve parts") data = response.json() part_results = data['results'] if batch and data.get('next'): while data['next']: if limit and len(part_results) >= limit: break response = self._request('GET', data['next']) data = response.json() part_results.extend(data['results']) return PartSet((Part(p, client=self) for p in part_results))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_property'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'CHAR_VALUE'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '39', '71', '92', '120', '157', '175', '191', '211', '220']},{'id': '25', 'type': 'if_statement', 'children': ['26', '33']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': '!='},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'MODEL'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'raise_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"The model should be of category MODEL"'},{'id': '39', 'type': 'if_statement', 'children': ['40', '47']},{'id': '40', 'type': 'not_operator', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'_VALUE'"},{'id': '47', 'type': 'block', 'children': ['48', '58']},{'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': 'warnings'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'concatenated_string', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"Please use the `PropertyType` enumeration to ensure providing correct "'},{'id': '56', 'type': 'string', 'children': [], 'value': '"values to the backend."'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'UserWarning'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'{}_VALUE'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '79']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'not'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Please provide a valid propertytype, please use one of `enums.PropertyType`. "'},{'id': '88', 'type': 'string', 'children': [], 'value': '"Got: \'{}\'"'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '92', 'type': 'if_statement', 'children': ['93', '113']},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '112'], 'value': 'and'},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '104', '105'], 'value': 'and'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '97', 'type': 'tuple', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'REFERENCE_VALUE'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'PropertyType'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'REFERENCES_VALUE'},{'id': '104', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '123', 'type': 'dictionary', 'children': ['124', '127', '132', '137', '144', '147', '152']},{'id': '124', 'type': 'pair', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '127', 'type': 'pair', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': '"part"'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '132', 'type': 'pair', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': '"description"'},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '136'], 'value': 'or'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '136', 'type': 'string', 'children': [], 'value': "''"},{'id': '137', 'type': 'pair', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': '"property_type"'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'property_type'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"value"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'default_value'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"unit"'},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '151'], 'value': 'or'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '151', 'type': 'string', 'children': [], 'value': "''"},{'id': '152', 'type': 'pair', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': '"options"'},{'id': '154', 'type': 'boolean_operator', 'children': ['155', '156'], 'value': 'or'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '156', 'type': 'dictionary', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166', '172']},{'id': '165', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': "'properties'"},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '175', 'type': 'if_statement', 'children': ['176', '185']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '180'], 'value': '!='},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'raise_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'string', 'children': [], 'value': '"Could not create property"'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'Property'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '198', 'type': 'argument_list', 'children': ['199', '208']},{'id': '199', 'type': 'subscript', 'children': ['200', '207']},{'id': '200', 'type': 'subscript', 'children': ['201', '206']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'prop'}
def create_property(self, model, name, description=None, property_type=PropertyType.CHAR_VALUE, default_value=None, unit=None, options=None): if model.category != Category.MODEL: raise IllegalArgumentError("The model should be of category MODEL") if not property_type.endswith('_VALUE'): warnings.warn("Please use the `PropertyType` enumeration to ensure providing correct " "values to the backend.", UserWarning) property_type = '{}_VALUE'.format(property_type.upper()) if property_type not in PropertyType.values(): raise IllegalArgumentError("Please provide a valid propertytype, please use one of `enums.PropertyType`. " "Got: '{}'".format(property_type)) if property_type in (PropertyType.REFERENCE_VALUE, PropertyType.REFERENCES_VALUE) and \ isinstance(default_value, (list, tuple)) and default_value: default_value = default_value[0] data = { "name": name, "part": model.id, "description": description or '', "property_type": property_type.upper(), "value": default_value, "unit": unit or '', "options": options or {} } response = self._request('POST', self._build_url('properties'), json=data) if response.status_code != requests.codes.created: raise APIError("Could not create property") prop = Property.create(response.json()['results'][0], client=self) model.properties.append(prop) return prop
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '23', '56', '76']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_request'},{'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': 'GET'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_parameter'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'default_sort'},{'id': '23', 'type': 'if_statement', 'children': ['24', '30', '46']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_request'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '30', 'type': 'block', 'children': ['31', '35']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '34', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '38', 'type': 'subscript', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_request'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'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': 'sort_order'},{'id': '51', 'type': 'string', 'children': [], 'value': "''"},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort_request'},{'id': '56', 'type': 'if_statement', 'children': ['57', '63']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_allowed_sort_fields'},{'id': '63', 'type': 'block', 'children': ['64', '70']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'default_sort_order'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'default_sort_field'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort_field'}
def set_sort(self, request): sort_request = request.GET.get(self.sort_parameter, self.default_sort) if sort_request.startswith('-'): sort_order = '-' sort_field = sort_request.split('-')[1] else: sort_order = '' sort_field = sort_request if not sort_field in self._allowed_sort_fields: sort_order = self.default_sort_order sort_field = self.default_sort_field return (sort_order, sort_field)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_sort_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '6', 'type': 'block', 'children': ['7', '43']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13', '24']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'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': 'next_sort'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '23'], 'value': '+'},{'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': 'toggle_sort_order'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '24', 'type': 'else_clause', 'children': ['25']},{'id': '25', 'type': 'block', 'children': ['26', '37']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'default_order_for_field'},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'subscript', 'children': ['31', '36']},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_allowed_sort_fields'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '36', 'type': 'string', 'children': [], 'value': "'default_direction'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'next_sort'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default_order_for_field'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_sort_string'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'next_sort'}
def get_next_sort_string(self, field): if field == self.sort_field: next_sort = self.toggle_sort_order() + field else: default_order_for_field = \ self._allowed_sort_fields[field]['default_direction'] next_sort = default_order_for_field + field return self.get_sort_string(next_sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_indicator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '6', 'type': 'block', 'children': ['7', '11', '33']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '10', 'type': 'string', 'children': [], 'value': "''"},{'id': '11', 'type': 'if_statement', 'children': ['12', '17']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '=='},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '17', 'type': 'block', 'children': ['18', '22']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '21', 'type': 'string', 'children': [], 'value': "'sort-asc'"},{'id': '22', 'type': 'if_statement', 'children': ['23', '28']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '27', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'indicator'},{'id': '32', 'type': 'string', 'children': [], 'value': "'sort-desc'"},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'indicator'}
def get_sort_indicator(self, field): indicator = '' if field == self.sort_field: indicator = 'sort-asc' if self.sort_order == '-': indicator = 'sort-desc' return indicator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_basic_sort_link'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '7', 'type': 'block', 'children': ['8', '16', '25', '64']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'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_querystring'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_next_sort_string'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '25', 'type': 'if_statement', 'children': ['26', '27', '47']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '27', 'type': 'block', 'children': ['28', '38']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_link'},{'id': '31', 'type': 'binary_operator', 'children': ['32', '37'], 'value': '+'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '36'], 'value': '+'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_string'},{'id': '38', 'type': 'if_statement', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '+='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_link'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '+'},{'id': '45', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49', '55']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_link'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '55', 'type': 'if_statement', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'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': 'sort_link'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'},{'id': '62', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sort_link'}
def get_basic_sort_link(self, request, field): query_string = self.get_querystring() sort_string = self.get_next_sort_string(field) if sort_string: sort_link = request.path + '?' + sort_string if query_string: sort_link += '&' + query_string else: sort_link = request.path if query_string: sort_link += '?' + query_string return sort_link
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download_as_pdf'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '16', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'paper_size'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'PaperSize'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'A4'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'paper_orientation'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'PaperOrientation'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'PORTRAIT'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'include_appendices'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '37', '50', '68', '81', '97', '112', '135', '249']},{'id': '25', 'type': 'if_statement', 'children': ['26', '28']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '36'], 'value': '+'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'string', 'children': [], 'value': "'.pdf'"},{'id': '37', 'type': 'if_statement', 'children': ['38', '45']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'.pdf'"},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '49', 'type': 'string', 'children': [], 'value': "'.pdf'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '59', 'type': 'argument_list', 'children': ['60', '67']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '62'], 'value': 'or'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'target_dir'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pdf_filename'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '71', 'type': 'dictionary', 'children': ['72', '75', '78']},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'papersize'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'paper_size'},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'orientation'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'paper_orientation'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'appendices'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'include_appendices'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'activity_export'"},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'activity_id'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109']},{'id': '107', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'request_params'},{'id': '112', 'type': 'if_statement', 'children': ['113', '122']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': '!='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'raise_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': '"Could not download PDF of activity {}"'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'include_appendices'},{'id': '137', 'type': 'block', 'children': ['138', '146', '160', '164', '234']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'urljoin'},{'id': '151', 'type': 'argument_list', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'api_root'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '159', 'type': 'string', 'children': [], 'value': "'download_url'"},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'while_statement', 'children': ['165', '168']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '<='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ASYNC_TIMEOUT_LIMIT'},{'id': '168', 'type': 'block', 'children': ['169', '183', '223', '227']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '183', 'type': 'if_statement', 'children': ['184', '193']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '=='},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '193', 'type': 'block', 'children': ['194', '222']},{'id': '194', 'type': 'with_statement', 'children': ['195', '205']},{'id': '195', 'type': 'with_clause', 'children': ['196']},{'id': '196', 'type': 'with_item', 'children': ['197']},{'id': '197', 'type': 'as_pattern', 'children': ['198', '203']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '202', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '203', 'type': 'as_pattern_target', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'for_statement', 'children': ['207', '208', '214']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '222', 'type': 'return_statement', 'children': []},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'augmented_assignment', 'children': ['225', '226'], 'value': '+='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ASYNC_REFRESH_INTERVAL'},{'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': 'time'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ASYNC_REFRESH_INTERVAL'},{'id': '234', 'type': 'raise_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'concatenated_string', 'children': ['241', '242']},{'id': '241', 'type': 'string', 'children': [], 'value': '"Could not download PDF of activity {} within the time-out limit of {} "'},{'id': '242', 'type': 'string', 'children': [], 'value': '"seconds"'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '244', 'type': 'argument_list', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'ASYNC_TIMEOUT_LIMIT'},{'id': '249', 'type': 'with_statement', 'children': ['250', '260']},{'id': '250', 'type': 'with_clause', 'children': ['251']},{'id': '251', 'type': 'with_item', 'children': ['252']},{'id': '252', 'type': 'as_pattern', 'children': ['253', '258']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'full_path'},{'id': '257', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '258', 'type': 'as_pattern_target', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'for_statement', 'children': ['262', '263', '269']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'chunk'}
def download_as_pdf(self, target_dir=None, pdf_filename=None, paper_size=PaperSize.A4, paper_orientation=PaperOrientation.PORTRAIT, include_appendices=False): if not pdf_filename: pdf_filename = self.name + '.pdf' if not pdf_filename.endswith('.pdf'): pdf_filename += '.pdf' full_path = os.path.join(target_dir or os.getcwd(), pdf_filename) request_params = { 'papersize': paper_size, 'orientation': paper_orientation, 'appendices': include_appendices } url = self._client._build_url('activity_export', activity_id=self.id) response = self._client._request('GET', url, params=request_params) if response.status_code != requests.codes.ok: raise APIError("Could not download PDF of activity {}".format(self.name)) if include_appendices: data = response.json() url = urljoin(self._client.api_root, data['download_url']) count = 0 while count <= ASYNC_TIMEOUT_LIMIT: response = self._client._request('GET', url=url) if response.status_code == requests.codes.ok: with open(full_path, 'wb') as f: for chunk in response.iter_content(1024): f.write(chunk) return count += ASYNC_REFRESH_INTERVAL time.sleep(ASYNC_REFRESH_INTERVAL) raise APIError("Could not download PDF of activity {} within the time-out limit of {} " "seconds".format(self.name, ASYNC_TIMEOUT_LIMIT)) with open(full_path, 'wb') as f: for chunk in response.iter_content(1024): f.write(chunk)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_project'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'env_filename'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ScopeStatus'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ACTIVE'},{'id': '30', 'type': 'block', 'children': ['31', '126', '264']},{'id': '31', 'type': 'if_statement', 'children': ['32', '43']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_FORCE_ENV_USE'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '42', 'type': 'False', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '60', '98']},{'id': '44', 'type': 'if_statement', 'children': ['45', '54']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_URL'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"Error: KECHAIN_URL should be provided as environment variable (use of env vars is enforced)"'},{'id': '60', 'type': 'if_statement', 'children': ['61', '90']},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': '()', 'children': ['63']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '72'], 'value': 'or'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_TOKEN'},{'id': '72', 'type': '()', 'children': ['73']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '82'], 'value': 'and'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_PASSWORD'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_PASSWORD'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'raise_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'concatenated_string', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Error: KECHAIN_TOKEN or KECHAIN_USERNAME and KECHAIN_PASSWORD should be provided as "'},{'id': '97', 'type': 'string', 'children': [], 'value': '"environment variable(s) (use of env vars is enforced)"'},{'id': '98', 'type': 'if_statement', 'children': ['99', '118']},{'id': '99', 'type': 'not_operator', 'children': ['100']},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '110'], 'value': 'or'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_SCOPE'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_SCOPE_ID'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'concatenated_string', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': '"Error: KECHAIN_SCOPE or KECHAIN_SCOPE_ID should be provided as environment variable "'},{'id': '125', 'type': 'string', 'children': [], 'value': '"(use of env vars is enforced)"'},{'id': '126', 'type': 'if_statement', 'children': ['127', '151', '199', '255']},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '139', '140'], 'value': 'or'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '132', 'type': 'argument_list', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_FORCE_ENV_USE'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '138', 'type': 'False', 'children': []},{'id': '139', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '140', 'type': 'not_operator', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'tuple', 'children': ['145', '146', '147', '148', '149', '150']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '151', 'type': 'block', 'children': ['152', '163', '175', '187']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Client'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'from_env'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'env_filename'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'env_filename'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_SCOPE_ID'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_SCOPE'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '192', 'type': 'argument_list', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_SCOPE_STATUS'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '198', 'type': 'None', 'children': []},{'id': '199', 'type': 'elif_clause', 'children': ['200', '230']},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '217', '218'], 'value': 'and'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '213'], 'value': 'and'},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '205'], 'value': 'and'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '205', 'type': '()', 'children': ['206']},{'id': '206', 'type': 'boolean_operator', 'children': ['207', '211'], 'value': 'or'},{'id': '207', 'type': '()', 'children': ['208']},{'id': '208', 'type': 'boolean_operator', 'children': ['209', '210'], 'value': 'and'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '211', 'type': '()', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '213', 'type': '()', 'children': ['214']},{'id': '214', 'type': 'boolean_operator', 'children': ['215', '216'], 'value': 'or'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '217', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '218', 'type': 'not_operator', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '223', 'type': 'argument_list', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'kecenv'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'KECHAIN_FORCE_ENV_USE'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '229', 'type': 'False', 'children': []},{'id': '230', 'type': 'block', 'children': ['231', '240']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Client'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '245', 'type': 'argument_list', 'children': ['246', '249', '252']},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '255', 'type': 'else_clause', 'children': ['256']},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'raise_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'concatenated_string', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': '"Error: insufficient arguments to connect to KE-chain. "'},{'id': '263', 'type': 'string', 'children': [], 'value': '"See documentation of `pykechain.get_project()`"'},{'id': '264', 'type': 'if_statement', 'children': ['265', '266', '279']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '272', 'type': 'argument_list', 'children': ['273', '276']},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'scope_id'},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'return_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '286', 'type': 'argument_list', 'children': ['287', '290']},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'status'}
def get_project(url=None, username=None, password=None, token=None, scope=None, scope_id=None, env_filename=None, status=ScopeStatus.ACTIVE): if env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False): if not os.getenv(kecenv.KECHAIN_URL): raise ClientError( "Error: KECHAIN_URL should be provided as environment variable (use of env vars is enforced)") if not (os.getenv(kecenv.KECHAIN_TOKEN) or (os.getenv(kecenv.KECHAIN_PASSWORD) and os.getenv(kecenv.KECHAIN_PASSWORD))): raise ClientError("Error: KECHAIN_TOKEN or KECHAIN_USERNAME and KECHAIN_PASSWORD should be provided as " "environment variable(s) (use of env vars is enforced)") if not (os.getenv(kecenv.KECHAIN_SCOPE) or os.getenv(kecenv.KECHAIN_SCOPE_ID)): raise ClientError("Error: KECHAIN_SCOPE or KECHAIN_SCOPE_ID should be provided as environment variable " "(use of env vars is enforced)") if env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False) or \ not any((url, username, password, token, scope, scope_id)): client = Client.from_env(env_filename=env_filename) scope_id = env(kecenv.KECHAIN_SCOPE_ID, default=None) scope = env(kecenv.KECHAIN_SCOPE, default=None) status = env(kecenv.KECHAIN_SCOPE_STATUS, default=None) elif (url and ((username and password) or (token)) and (scope or scope_id)) and \ not env.bool(kecenv.KECHAIN_FORCE_ENV_USE, default=False): client = Client(url=url) client.login(username=username, password=password, token=token) else: raise ClientError("Error: insufficient arguments to connect to KE-chain. " "See documentation of `pykechain.get_project()`") if scope_id: return client.scope(pk=scope_id, status=status) else: return client.scope(name=scope, status=status)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'options'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'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': 'generator_expression', 'children': ['10', '13', '24']},{'id': '10', 'type': 'tuple', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '17']},{'id': '14', 'type': 'tuple_pattern', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'if_clause', 'children': ['25']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'__'"}
def options(cls): return sorted((value, name) for (name, value) in cls.__dict__.items() if not name.startswith('__'))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'edit'},{'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': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '26', '52', '78', '104', '115', '142', '163', '172']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '20', 'type': 'dictionary', 'children': ['21']},{'id': '21', 'type': 'pair', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'block', 'children': ['29', '42']},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"name should be provided as a string"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'dictionary', 'children': ['49']},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '52', 'type': 'if_statement', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '54', 'type': 'block', 'children': ['55', '68']},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"description should be provided as a string"'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'dictionary', 'children': ['75']},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '80', 'type': 'block', 'children': ['81', '94']},{'id': '81', 'type': 'if_statement', 'children': ['82', '88']},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"description should be provided as a string"'},{'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': 'update_dict'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'dictionary', 'children': ['101']},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'script_version'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '104', 'type': 'if_statement', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'update_dict'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'dictionary_splat', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '139']},{'id': '125', 'type': 'string', 'children': [], 'value': "'PUT'"},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'service'"},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'service_id'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '142', 'type': 'if_statement', 'children': ['143', '152']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '!='},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'raise_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': '"Could not update Service ({})"'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '163', 'type': 'if_statement', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'version'}
def edit(self, name=None, description=None, version=None, **kwargs): update_dict = {'id': self.id} if name: if not isinstance(name, str): raise IllegalArgumentError("name should be provided as a string") update_dict.update({'name': name}) if description: if not isinstance(description, str): raise IllegalArgumentError("description should be provided as a string") update_dict.update({'description': description}) if version: if not isinstance(version, str): raise IllegalArgumentError("description should be provided as a string") update_dict.update({'script_version': version}) if kwargs: update_dict.update(**kwargs) response = self._client._request('PUT', self._client._build_url('service', service_id=self.id), json=update_dict) if response.status_code != requests.codes.ok: raise APIError("Could not update Service ({})".format(response)) if name: self.name = name if version: self.version = version
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'children'},{'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']},{'id': '8', 'type': 'if_statement', 'children': ['9', '11', '47']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '43']},{'id': '12', 'type': 'if_statement', 'children': ['13', '17']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_cached_children'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_cached_children'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '32', 'type': 'argument_list', 'children': ['33', '38']},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_cached_children'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '56', 'type': 'argument_list', 'children': ['57', '62', '67']},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '67', 'type': 'dictionary_splat', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def children(self, **kwargs): if not kwargs: if not self._cached_children: self._cached_children = list(self._client.parts(parent=self.id, category=self.category)) return self._cached_children else: return self._client.parts(parent=self.id, category=self.category, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'},{'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': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'block', 'children': ['17', '21', '27', '64']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '20', 'type': 'string', 'children': [], 'value': "'bulk_update_properties'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'request_body'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'for_statement', 'children': ['28', '31', '36']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '42', '49']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'is_uuid'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'request_body'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '63']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'request_body'},{'id': '55', 'type': 'attribute', 'children': ['56', '62']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '64', 'type': 'if_statement', 'children': ['65', '77', '171']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'and'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '76'], 'value': '>'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'block', 'children': ['78', '94', '144']},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'if_statement', 'children': ['82', '88']},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"Name of the part should be provided as a string"'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '118', '136']},{'id': '104', 'type': 'string', 'children': [], 'value': "'PUT'"},{'id': '105', 'type': 'call', 'children': ['106', '111']},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'part'"},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'part_id'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '122', 'type': 'argument_list', 'children': ['123', '126', '134']},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'request_body'},{'id': '134', 'type': 'dictionary_splat', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'select_action'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '144', 'type': 'if_statement', 'children': ['145', '154']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '!='},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'raise_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'{}: {}'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '163', 'type': 'argument_list', 'children': ['164', '168']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '171', 'type': 'else_clause', 'children': ['172']},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'for_statement', 'children': ['174', '177', '182']},{'id': '174', 'type': 'pattern_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '193']},{'id': '185', 'type': 'attribute', 'children': ['186', '192']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'property_value'}
def update(self, name=None, update_dict=None, bulk=True, **kwargs): action = 'bulk_update_properties' request_body = dict() for prop_name_or_id, property_value in update_dict.items(): if is_uuid(prop_name_or_id): request_body[prop_name_or_id] = property_value else: request_body[self.property(prop_name_or_id).id] = property_value if bulk and len(update_dict.keys()) > 1: if name: if not isinstance(name, str): raise IllegalArgumentError("Name of the part should be provided as a string") r = self._client._request('PUT', self._client._build_url('part', part_id=self.id), data=dict(name=name, properties=json.dumps(request_body), **kwargs), params=dict(select_action=action)) if r.status_code != requests.codes.ok: raise APIError('{}: {}'.format(str(r), r.content)) else: for property_name, property_value in update_dict.items(): self.property(property_name).value = property_value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_with_properties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '17', 'type': 'block', 'children': ['18', '32', '40', '44', '50', '87']},{'id': '18', 'type': 'if_statement', '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': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'INSTANCE'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'raise_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"Part should be of category INSTANCE"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '37'], 'value': 'or'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '43', 'type': 'string', 'children': [], 'value': "'new_instance_with_properties'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'properties_update_dict'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'for_statement', 'children': ['51', '54', '59']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '65', '72']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_uuid'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'properties_update_dict'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '86']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'properties_update_dict'},{'id': '78', 'type': 'attribute', 'children': ['79', '85']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'prop_name_or_id'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'property_value'},{'id': '87', 'type': 'if_statement', 'children': ['88', '89', '190']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '89', 'type': 'block', 'children': ['90', '145', '172']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_request'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '109', '137']},{'id': '100', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_build_url'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'parts'"},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117', '122', '127', '135']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'properties_update_dict'},{'id': '135', 'type': 'dictionary_splat', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'select_action'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '145', 'type': 'if_statement', 'children': ['146', '155']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '!='},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': "'{}: {}'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165', '169']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'Part'},{'id': '175', 'type': 'argument_list', 'children': ['176', '185']},{'id': '176', 'type': 'subscript', 'children': ['177', '184']},{'id': '177', 'type': 'subscript', 'children': ['178', '183']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192', '204', '216']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'new_part'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'new_part'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '209', 'type': 'argument_list', 'children': ['210', '213']},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'update_dict'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'bulk'},{'id': '216', 'type': 'return_statement', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'new_part'}
def add_with_properties(self, model, name=None, update_dict=None, bulk=True, **kwargs): if self.category != Category.INSTANCE: raise APIError("Part should be of category INSTANCE") name = name or model.name action = 'new_instance_with_properties' properties_update_dict = dict() for prop_name_or_id, property_value in update_dict.items(): if is_uuid(prop_name_or_id): properties_update_dict[prop_name_or_id] = property_value else: properties_update_dict[model.property(prop_name_or_id).id] = property_value if bulk: r = self._client._request('POST', self._client._build_url('parts'), data=dict( name=name, model=model.id, parent=self.id, properties=json.dumps(properties_update_dict), **kwargs ), params=dict(select_action=action)) if r.status_code != requests.codes.created: raise APIError('{}: {}'.format(str(r), r.content)) return Part(r.json()['results'][0], client=self._client) else: new_part = self.add(model, name=name) new_part.update(update_dict=update_dict, bulk=bulk) return new_part
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'move'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'include_instances'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '26']},{'id': '16', 'type': 'if_statement', 'children': ['17', '19']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'if_statement', 'children': ['27', '42', '129', '191']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '35'], 'value': 'and'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'MODEL'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'MODEL'},{'id': '42', 'type': 'block', 'children': ['43', '61', '121', '127']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'relocate_model'},{'id': '48', 'type': 'argument_list', 'children': ['49', '52', '55', '58']},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '61', 'type': 'if_statement', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'include_instances'},{'id': '63', 'type': 'block', 'children': ['64', '75', '86']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'retrieve_instances_to_copied'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'retrieve_parent_instances'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'for_statement', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'parent_instance'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'retrieve_parent_instances'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'retrieve_instances_to_copied'},{'id': '93', 'type': 'block', 'children': ['94', '100']},{'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': 'instance'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'populate_descendants'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'move_part_instance'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107', '110', '113', '118']},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'part_instance'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parent_instance'},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'part_model'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'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': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'moved_model'},{'id': '129', 'type': 'elif_clause', 'children': ['130', '145']},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '138'], 'value': 'and'},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'INSTANCE'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '=='},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'INSTANCE'},{'id': '145', 'type': 'block', 'children': ['146', '164', '189']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'relocate_instance'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155', '158', '161']},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'target_parent'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'include_children'},{'id': '164', 'type': 'try_statement', 'children': ['165', '172']},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'except_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'APIError'},{'id': '174', 'type': 'block', 'children': ['175', '183']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'model_of_instance'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'model_of_instance'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'moved_instance'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'raise_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'IllegalArgumentError'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': '\'part "{}" and target parent "{}" must have the same category\''}
def move(self, target_parent, name=None, include_children=True, include_instances=True): if not name: name = self.name if self.category == Category.MODEL and target_parent.category == Category.MODEL: moved_model = relocate_model(part=self, target_parent=target_parent, name=name, include_children=include_children) if include_instances: retrieve_instances_to_copied = list(self.instances()) retrieve_parent_instances = list(target_parent.instances()) for parent_instance in retrieve_parent_instances: for instance in retrieve_instances_to_copied: instance.populate_descendants() move_part_instance(part_instance=instance, target_parent=parent_instance, part_model=self, name=instance.name, include_children=include_children) self.delete() return moved_model elif self.category == Category.INSTANCE and target_parent.category == Category.INSTANCE: moved_instance = relocate_instance(part=self, target_parent=target_parent, name=name, include_children=include_children) try: self.delete() except APIError: model_of_instance = self.model() model_of_instance.delete() return moved_instance else: raise IllegalArgumentError('part "{}" and target parent "{}" must have the same category')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '69']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '51', '54', '57', '60', '63', '66']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'graph_attr'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '36', 'type': 'default_parameter', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'edge_attr'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '42', 'type': 'default_parameter', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'node_styles'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '45', 'type': 'default_parameter', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'node_data'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '48', 'type': 'default_parameter', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'node_function'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '51', 'type': 'default_parameter', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '54', 'type': 'default_parameter', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'max_lines'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '57', 'type': 'default_parameter', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max_width'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '60', 'type': 'default_parameter', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'default_parameter', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sites'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'default_parameter', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '68', 'type': 'False', 'children': []},{'id': '69', 'type': 'block', 'children': ['70', '101', '144', '164', '171', '178', '201', '207', '222', '278']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '73', 'type': 'dictionary', 'children': ['74', '77', '80', '83', '86', '89', '92', '95', '98']},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '80', 'type': 'pair', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'format'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'engine'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'encoding'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'graph_attr'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'graph_attr'},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'node_attr'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'edge_attr'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'edge_attr'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'body'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '104', 'type': 'dictionary', 'children': ['105', '126', '129', '132', '135', '138', '141']},{'id': '105', 'type': 'pair', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': "'digraph'"},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '125'], 'value': 'or'},{'id': '108', 'type': 'dictionary_comprehension', 'children': ['109', '112', '121']},{'id': '109', 'type': 'pair', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '116']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'if_clause', 'children': ['122']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '126', 'type': 'pair', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'node_styles'"},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'node_styles'},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'node_data'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'node_data'},{'id': '132', 'type': 'pair', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'node_function'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'node_function'},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'edge_data'"},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': "'max_lines'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'max_lines'},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': "'max_width'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'max_width'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '147', 'type': 'dictionary_comprehension', 'children': ['148', '151', '160']},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '151', 'type': 'for_in_clause', 'children': ['152', '155']},{'id': '152', 'type': 'pattern_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'if_clause', 'children': ['161']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'is'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '164', 'type': 'import_from_statement', 'children': ['165', '169']},{'id': '165', 'type': 'relative_import', 'children': ['166', '167']},{'id': '166', 'type': 'import_prefix', 'children': []},{'id': '167', 'type': 'dotted_name', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'drw'},{'id': '169', 'type': 'dotted_name', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'SiteMap'},{'id': '171', 'type': 'import_from_statement', 'children': ['172', '176']},{'id': '172', 'type': 'relative_import', 'children': ['173', '174']},{'id': '173', 'type': 'import_prefix', 'children': []},{'id': '174', 'type': 'dotted_name', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '176', 'type': 'dotted_name', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Solution'},{'id': '178', 'type': 'if_statement', 'children': ['179', '188', '193']},{'id': '179', 'type': 'boolean_operator', 'children': ['180', '183'], 'value': 'and'},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'is'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '182', 'type': 'None', 'children': []},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'Solution'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '198', 'type': 'boolean_operator', 'children': ['199', '200'], 'value': 'or'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '200', 'type': 'False', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sitemap'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'SiteMap'},{'id': '206', 'type': 'argument_list', 'children': []},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'sitemap'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'add_items'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214', '217', '220']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '220', 'type': 'dictionary_splat', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '222', 'type': 'if_statement', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '224', 'type': 'block', 'children': ['225', '228', '238']},{'id': '225', 'type': 'import_statement', 'children': ['226']},{'id': '226', 'type': 'dotted_name', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '231', 'type': 'boolean_operator', 'children': ['232', '233'], 'value': 'or'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'if_statement', 'children': ['239', '242', '258']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'is'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'sites'},{'id': '241', 'type': 'None', 'children': []},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sitemap'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '248', 'type': 'argument_list', 'children': ['249', '252', '255']},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '254', 'type': 'True', 'children': []},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '258', 'type': 'else_clause', 'children': ['259']},{'id': '259', 'type': 'block', 'children': ['260']},{'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': 'sites'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'sitemap'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272', '275']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '274', 'type': 'True', 'children': []},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '278', 'type': 'return_statement', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sitemap'}
def plot(self, workflow=None, view=True, depth=-1, name=NONE, comment=NONE, format=NONE, engine=NONE, encoding=NONE, graph_attr=NONE, node_attr=NONE, edge_attr=NONE, body=NONE, node_styles=NONE, node_data=NONE, node_function=NONE, edge_data=NONE, max_lines=NONE, max_width=NONE, directory=None, sites=None, index=False): d = { 'name': name, 'comment': comment, 'format': format, 'engine': engine, 'encoding': encoding, 'graph_attr': graph_attr, 'node_attr': node_attr, 'edge_attr': edge_attr, 'body': body, } options = { 'digraph': {k: v for k, v in d.items() if v is not NONE} or NONE, 'node_styles': node_styles, 'node_data': node_data, 'node_function': node_function, 'edge_data': edge_data, 'max_lines': max_lines, 'max_width': max_width, } options = {k: v for k, v in options.items() if v is not NONE} from .drw import SiteMap from .sol import Solution if workflow is None and isinstance(self, Solution): workflow = True else: workflow = workflow or False sitemap = SiteMap() sitemap.add_items(self, workflow=workflow, depth=depth, **options) if view: import tempfile directory = directory or tempfile.mkdtemp() if sites is None: sitemap.render(directory=directory, view=True, index=index) else: sites.add(sitemap.site(directory, view=True, index=index)) return sitemap
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lookup_url'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '23', '30']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Gets a proxy reference to the actor indicated by the URL in the\n parameters. It can be a local reference or a remote direction to\n another host.\n This method can be called remotely synchronously.\n :param srt. url: address that identifies an actor.\n :param class klass: the class of the actor.\n :param srt. module: if the actor class is not in the calling module,\n you need to specify the module where it is here. Also, the *klass*\n parameter change to be a string.\n :return: :class:`~.Proxy` of the actor requested.\n :raises: :class:`NotFoundError`, if the URL specified do not\n correspond to any actor in the host.\n :raises: :class:`HostDownError` if the host is down.\n :raises: :class:`HostError` if there is an error looking for\n the actor in another server.\n '''"},{'id': '13', 'type': 'if_statement', 'children': ['14', '18']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'alive'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'HostDownError'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'aurl'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '30', 'type': 'if_statement', 'children': ['31', '37', '65']},{'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': 'is_local'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'aurl'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '48', '54']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'actors'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Proxy'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'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': 'actors'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'try_statement', 'children': ['68', '181', '185']},{'id': '68', 'type': 'block', 'children': ['69', '79', '163', '176']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dispatcher'},{'id': '72', 'type': 'subscript', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'actors'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'aurl'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '137', '154']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'try_statement', 'children': ['85', '111']},{'id': '85', 'type': 'block', 'children': ['86', '103']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'module_'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': '__import__'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '96', '99', '101']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'list', 'children': ['100'], 'value': '[klass]'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '101', 'type': 'unary_operator', 'children': ['102'], 'value': '-'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'klass_'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'module_'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '111', 'type': 'except_clause', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'raise_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'HostError'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '133'], 'value': '+'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '132'], 'value': '+'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '131'], 'value': '+'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '130'], 'value': '+'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '129'], 'value': '+'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '128'], 'value': '+'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'},{'id': '126', 'type': 'string', 'children': [], 'value': '"At lookup_url: "'},{'id': '127', 'type': 'string', 'children': [], 'value': '"Import failed for module "'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '129', 'type': 'string', 'children': [], 'value': '", class "'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '131', 'type': 'string', 'children': [], 'value': '". Check this values for the lookup."'},{'id': '132', 'type': 'string', 'children': [], 'value': '" ERROR: "'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '137', 'type': 'elif_clause', 'children': ['138', '149']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '142', 'type': 'tuple', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'TypeType'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ClassType'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'klass_'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'HostError'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'},{'id': '161', 'type': 'string', 'children': [], 'value': '"The class specified to look up is"'},{'id': '162', 'type': 'string', 'children': [], 'value': '" not a class."'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'remote_actor'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'actor'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ActorRef'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'klass_'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dispatcher'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'Proxy'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'remote_actor'},{'id': '181', 'type': 'except_clause', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'HostError'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'raise_statement', 'children': []},{'id': '185', 'type': 'except_clause', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'raise_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'HostError'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '199'], 'value': '+'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '198'], 'value': '+'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'},{'id': '196', 'type': 'string', 'children': [], 'value': '"ERROR looking for the actor on another "'},{'id': '197', 'type': 'string', 'children': [], 'value': '"server. Hosts must "'},{'id': '198', 'type': 'string', 'children': [], 'value': '"be in http to work properly. "'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'e'}
def lookup_url(self, url, klass, module=None): ''' Gets a proxy reference to the actor indicated by the URL in the parameters. It can be a local reference or a remote direction to another host. This method can be called remotely synchronously. :param srt. url: address that identifies an actor. :param class klass: the class of the actor. :param srt. module: if the actor class is not in the calling module, you need to specify the module where it is here. Also, the *klass* parameter change to be a string. :return: :class:`~.Proxy` of the actor requested. :raises: :class:`NotFoundError`, if the URL specified do not correspond to any actor in the host. :raises: :class:`HostDownError` if the host is down. :raises: :class:`HostError` if there is an error looking for the actor in another server. ''' if not self.alive: raise HostDownError() aurl = urlparse(url) if self.is_local(aurl): if url not in self.actors.keys(): raise NotFoundError(url) else: return Proxy(self.actors[url]) else: try: dispatcher = self.actors[aurl.scheme] if module is not None: try: module_ = __import__(module, globals(), locals(), [klass], -1) klass_ = getattr(module_, klass) except Exception, e: raise HostError("At lookup_url: " + "Import failed for module " + module + ", class " + klass + ". Check this values for the lookup." + " ERROR: " + str(e)) elif isinstance(klass, (types.TypeType, types.ClassType)): klass_ = klass else: raise HostError("The class specified to look up is" + " not a class.") remote_actor = actor.ActorRef(url, klass_, dispatcher.channel) return Proxy(remote_actor) except HostError: raise except Exception, e: raise HostError("ERROR looking for the actor on another " + "server. Hosts must " + "be in http to work properly. " + str(e))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_rapid_streamflow'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path_to_rapid_qout'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'connection_list_file'},{'id': '7', 'type': 'block', 'children': ['8', '21']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ihg_filename'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': "'{0}.ihg'"},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'project_manager'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '21', 'type': 'with_statement', 'children': ['22', '32']},{'id': '22', 'type': 'with_clause', 'children': ['23']},{'id': '23', 'type': 'with_item', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tmp_chdir'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'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': 'project_manager'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'project_directory'},{'id': '32', 'type': 'block', 'children': ['33', '37', '203']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '36', 'type': 'list', 'children': [], 'value': '[]'},{'id': '37', 'type': 'with_statement', 'children': ['38', '52']},{'id': '38', 'type': 'with_clause', 'children': ['39']},{'id': '39', 'type': 'with_item', 'children': ['40']},{'id': '40', 'type': 'as_pattern', 'children': ['41', '50']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'RAPIDDataset'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'path_to_rapid_qout'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'out_tzinfo'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '50', 'type': 'as_pattern_target', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'qout_nc'},{'id': '52', 'type': 'block', 'children': ['53', '71', '134']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'qout_nc'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_time_index_range'},{'id': '60', 'type': 'argument_list', 'children': ['61', '66']},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'date_search_start'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'simulation_start'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'date_search_end'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '71', 'type': 'if_statement', 'children': ['72', '78']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': '>'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'block', 'children': ['79', '93']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'qout_nc'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'get_time_array'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'return_datetime'},{'id': '89', 'type': 'True', 'children': []},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'time_index_array'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '93', 'type': 'if_statement', 'children': ['94', '99']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': 'is'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'simulation_start'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '108']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '=='},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'simulation_start'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'block', 'children': ['109', '118', '126']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'concatenated_string', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': '"First timestep of streamflow skipped "'},{'id': '117', 'type': 'string', 'children': [], 'value': '"in order for GSSHA to capture the streamflow."'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '123', 'type': 'slice', 'children': ['124', '125']},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '131', 'type': 'slice', 'children': ['132', '133']},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'colon', 'children': []},{'id': '134', 'type': 'if_statement', 'children': ['135', '141', '194']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '140'], 'value': '>'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'block', 'children': ['142', '148', '162', '178']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'start_datetime'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'if_statement', 'children': ['149', '154']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': 'is'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'simulation_start'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_update_simulation_start'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'start_datetime'},{'id': '162', 'type': 'if_statement', 'children': ['163', '168']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': 'is'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '167', 'type': 'None', 'children': []},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'time_array'},{'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'qout_nc'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'write_flows_to_gssha_time_series_ihg'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186', '189']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ihg_filename'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'connection_list_file'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'date_search_start'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'start_datetime'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'date_search_end'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '194', 'type': 'else_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': '"No streamflow values found in time range ..."'},{'id': '203', 'type': 'if_statement', 'children': ['204', '210', '260']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '209'], 'value': '>'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'time_index_range'},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'block', 'children': ['211', '217', '232', '241', '254']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_update_simulation_start_cards'},{'id': '216', 'type': 'argument_list', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_update_card'},{'id': '222', 'type': 'argument_list', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': '"END_TIME"'},{'id': '224', 'type': 'call', 'children': ['225', '230']},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'string', 'children': [], 'value': '"%Y %m %d %H %M"'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': '_update_card'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239', '240']},{'id': '238', 'type': 'string', 'children': [], 'value': '"CHAN_POINT_INPUT"'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ihg_filename'},{'id': '240', 'type': 'True', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'set_simulation_duration'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '-'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'simulation_end'},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'simulation_start'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': '_update_gmt'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'else_clause', 'children': ['261']},{'id': '261', 'type': 'block', 'children': ['262', '269']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'ihg_filename'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '276']},{'id': '271', 'type': 'attribute', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'project_manager'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'deleteCard'},{'id': '276', 'type': 'argument_list', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': "'CHAN_POINT_INPUT'"},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'db_session'}
def prepare_rapid_streamflow(self, path_to_rapid_qout, connection_list_file): ihg_filename = '{0}.ihg'.format(self.project_manager.name) with tmp_chdir(self.project_manager.project_directory): time_index_range = [] with RAPIDDataset(path_to_rapid_qout, out_tzinfo=self.tz) as qout_nc: time_index_range = qout_nc.get_time_index_range(date_search_start=self.simulation_start, date_search_end=self.simulation_end) if len(time_index_range) > 0: time_array = qout_nc.get_time_array(return_datetime=True, time_index_array=time_index_range) if self.simulation_start is not None: if self.simulation_start == time_array[0]: log.warning("First timestep of streamflow skipped " "in order for GSSHA to capture the streamflow.") time_index_range = time_index_range[1:] time_array = time_array[1:] if len(time_index_range) > 0: start_datetime = time_array[0] if self.simulation_start is None: self._update_simulation_start(start_datetime) if self.simulation_end is None: self.simulation_end = time_array[-1] qout_nc.write_flows_to_gssha_time_series_ihg(ihg_filename, connection_list_file, date_search_start=start_datetime, date_search_end=self.simulation_end, ) else: log.warning("No streamflow values found in time range ...") if len(time_index_range) > 0: self._update_simulation_start_cards() self._update_card("END_TIME", self.simulation_end.strftime("%Y %m %d %H %M")) self._update_card("CHAN_POINT_INPUT", ihg_filename, True) self.set_simulation_duration(self.simulation_end-self.simulation_start) self._update_gmt() else: os.remove(ihg_filename) self.project_manager.deleteCard('CHAN_POINT_INPUT', self.db_session)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stencil'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '6', 'type': 'block', 'children': ['7', '16', '25', '34', '73', '87', '107', '130', '145', '156', '344', '354', '373', '382', '400']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'alnfile'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'alnfile'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'gtypefile'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'gtypefile'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': "'grpfile'"},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39', '51']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'grpfile2chk'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'DATA_DIR'},{'id': '50', 'type': 'string', 'children': [], 'value': "'ref.gene2transcripts.tsv'"},{'id': '51', 'type': 'if_statement', 'children': ['52', '60', '65']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'grpfile2chk'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'grpfile2chk'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'print_statement', 'children': ['68', '72']},{'id': '68', 'type': 'chevron', 'children': ['69']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '72', 'type': 'string', 'children': [], 'value': "'[gbrs::stencil] A group file is *not* given. Genotype will be stenciled as is.'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'emase'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'AlignmentPropertyMatrix'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84']},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'h5file'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'alnfile'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'hid'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '95', 'type': 'argument_list', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'hname'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'num_haplotypes'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '115', 'type': 'argument_list', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'gname'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'gname'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'gtmask'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'tuple', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'num_haplotypes'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'num_loci'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'gtcall_g'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'fromkeys'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'gname'},{'id': '156', 'type': 'with_statement', 'children': ['157', '166']},{'id': '157', 'type': 'with_clause', 'children': ['158']},{'id': '158', 'type': 'with_item', 'children': ['159']},{'id': '159', 'type': 'as_pattern', 'children': ['160', '164']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'gtypefile'},{'id': '164', 'type': 'as_pattern_target', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'if_statement', 'children': ['168', '171', '276']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'grpfile'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '183']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'gtcall_t'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'fromkeys'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lname'},{'id': '183', 'type': 'for_statement', 'children': ['184', '185', '190']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'curline'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'dropwhile'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'is_comment'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '190', 'type': 'block', 'children': ['191', '204', '214', '220', '235', '250', '262']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '194', 'type': 'call', 'children': ['195', '202']},{'id': '195', 'type': 'attribute', 'children': ['196', '201']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'curline'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '209']},{'id': '206', 'type': 'pattern_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '211', 'type': 'slice', 'children': ['212', '213']},{'id': '212', 'type': 'colon', 'children': []},{'id': '213', 'type': 'integer', 'children': [], 'value': '2'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'gtcall_g'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'hid2set'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'list_comprehension', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'hid'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '232', 'type': 'for_in_clause', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tid2set'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '261']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'gtmask'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'hid2set'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'tid2set'},{'id': '261', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '262', 'type': 'for_statement', 'children': ['263', '264', '265']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'tid2set'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '275']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'gtcall_t'},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'lname'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '276', 'type': 'else_clause', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'for_statement', 'children': ['279', '280', '285']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'curline'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'dropwhile'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'is_comment'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '285', 'type': 'block', 'children': ['286', '299', '309', '315', '330']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '289', 'type': 'call', 'children': ['290', '297']},{'id': '290', 'type': 'attribute', 'children': ['291', '296']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'curline'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '295', 'type': 'argument_list', 'children': []},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '304']},{'id': '301', 'type': 'pattern_list', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '306', 'type': 'slice', 'children': ['307', '308']},{'id': '307', 'type': 'colon', 'children': []},{'id': '308', 'type': 'integer', 'children': [], 'value': '2'},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '314']},{'id': '311', 'type': 'subscript', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'gtcall_g'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'hid2set'},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'list_comprehension', 'children': ['324', '327']},{'id': '324', 'type': 'subscript', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'hid'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '327', 'type': 'for_in_clause', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '343']},{'id': '332', 'type': 'subscript', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'gtmask'},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '338', 'type': 'argument_list', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'hid2set'},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '343', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '349', 'type': 'argument_list', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'gtmask'},{'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '353', 'type': 'integer', 'children': [], 'value': '2'},{'id': '354', 'type': 'for_statement', 'children': ['355', '356', '362']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'num_haplotypes'},{'id': '362', 'type': 'block', 'children': ['363']},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'call', 'children': ['365', '372']},{'id': '365', 'type': 'attribute', 'children': ['366', '371']},{'id': '366', 'type': 'subscript', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'eliminate_zeros'},{'id': '372', 'type': 'argument_list', 'children': []},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'string', 'children': [], 'value': "'outfile'"},{'id': '382', 'type': 'if_statement', 'children': ['383', '386']},{'id': '383', 'type': 'comparison_operator', 'children': ['384', '385'], 'value': 'is'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '385', 'type': 'None', 'children': []},{'id': '386', 'type': 'block', 'children': ['387']},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'assignment', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '390', 'type': 'binary_operator', 'children': ['391', '392'], 'value': '+'},{'id': '391', 'type': 'string', 'children': [], 'value': "'gbrs.stenciled.'"},{'id': '392', 'type': 'call', 'children': ['393', '398']},{'id': '393', 'type': 'attribute', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'alnfile'},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'alnmat'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'keyword_argument', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'h5file'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'outfile'}
def stencil(**kwargs): alnfile = kwargs.get('alnfile') gtypefile = kwargs.get('gtypefile') grpfile = kwargs.get('grpfile') if grpfile is None: grpfile2chk = os.path.join(DATA_DIR, 'ref.gene2transcripts.tsv') if os.path.exists(grpfile2chk): grpfile = grpfile2chk else: print >> sys.stderr, '[gbrs::stencil] A group file is *not* given. Genotype will be stenciled as is.' alnmat = emase.AlignmentPropertyMatrix(h5file=alnfile, grpfile=grpfile) hid = dict(zip(alnmat.hname, np.arange(alnmat.num_haplotypes))) gid = dict(zip(alnmat.gname, np.arange(len(alnmat.gname)))) gtmask = np.zeros((alnmat.num_haplotypes, alnmat.num_loci)) gtcall_g = dict.fromkeys(alnmat.gname) with open(gtypefile) as fh: if grpfile is not None: gtcall_t = dict.fromkeys(alnmat.lname) for curline in dropwhile(is_comment, fh): item = curline.rstrip().split("\t") g, gt = item[:2] gtcall_g[g] = gt hid2set = np.array([hid[c] for c in gt]) tid2set = np.array(alnmat.groups[gid[g]]) gtmask[np.meshgrid(hid2set, tid2set)] = 1.0 for t in tid2set: gtcall_t[alnmat.lname[t]] = gt else: for curline in dropwhile(is_comment, fh): item = curline.rstrip().split("\t") g, gt = item[:2] gtcall_g[g] = gt hid2set = np.array([hid[c] for c in gt]) gtmask[np.meshgrid(hid2set, gid[g])] = 1.0 alnmat.multiply(gtmask, axis=2) for h in xrange(alnmat.num_haplotypes): alnmat.data[h].eliminate_zeros() outfile = kwargs.get('outfile') if outfile is None: outfile = 'gbrs.stenciled.' + os.path.basename(alnfile) alnmat.save(h5file=outfile)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_tracks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'block', 'children': ['9', '11', '15', '29', '40', '316', '353']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'''assumes eastward motion'''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tracks'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '20', 'type': 'expression_list', 'children': ['21', '25']},{'id': '21', 'type': 'list', 'children': ['22'], 'value': '[lat[0]]'},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'list', 'children': ['26'], 'value': '[lon[0]]'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '32', 'type': 'list_comprehension', 'children': ['33', '37']},{'id': '33', 'type': 'list', 'children': ['34'], 'value': '[z[0]]'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '50']},{'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': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '50', 'type': 'block', 'children': ['51', '60', '79', '94', '112', '130']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'for_statement', 'children': ['61', '64', '69']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'z'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'd1'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '89'], 'value': '-'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '-'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'd2'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '109'], 'value': '-'},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '108'], 'value': '+'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '-'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'integer', 'children': [], 'value': '360'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'd3'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '124'], 'value': '-'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '-'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '+'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'integer', 'children': [], 'value': '360'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134', '216', '305']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '<'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'd2'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'd1'},{'id': '134', 'type': 'block', 'children': ['135', '146', '177', '189', '203']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '-'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'integer', 'children': [], 'value': '360'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'tracks'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '166', '167'], 'value': '+'},{'id': '153', 'type': 'list', 'children': ['154', '160'], 'value': '[np.array(lt),np.array(ln)]'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '166', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '167', 'type': 'list_comprehension', 'children': ['168', '174']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '180', 'type': 'list', 'children': ['181', '186'], 'value': '[lat[i-1],lat[i]]'},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '-'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '192', 'type': 'list', 'children': ['193', '200'], 'value': '[lon[i-1]+360,lon[i]]'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '199'], 'value': '+'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '-'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'integer', 'children': [], 'value': '360'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '206', 'type': 'list_comprehension', 'children': ['207', '213']},{'id': '207', 'type': 'list', 'children': ['208'], 'value': '[z[i-1]]'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '-'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1'},{'id': '213', 'type': 'for_in_clause', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '216', 'type': 'elif_clause', 'children': ['217', '220']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '<'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'd3'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'd1'},{'id': '220', 'type': 'block', 'children': ['221', '232', '263', '275', '289']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'binary_operator', 'children': ['228', '231'], 'value': '+'},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'integer', 'children': [], 'value': '360'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'tracks'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'binary_operator', 'children': ['239', '252', '253'], 'value': '+'},{'id': '239', 'type': 'list', 'children': ['240', '246'], 'value': '[np.array(lt),np.array(ln)]'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '252', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '253', 'type': 'list_comprehension', 'children': ['254', '260']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '266', 'type': 'list', 'children': ['267', '272'], 'value': '[lat[i-1],lat[i]]'},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '-'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'lat'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '278', 'type': 'list', 'children': ['279', '286'], 'value': '[lon[i-1]-360,lon[i]]'},{'id': '279', 'type': 'binary_operator', 'children': ['280', '285'], 'value': '-'},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '284'], 'value': '-'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '284', 'type': 'integer', 'children': [], 'value': '1'},{'id': '285', 'type': 'integer', 'children': [], 'value': '360'},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '292', 'type': 'list_comprehension', 'children': ['293', '302']},{'id': '293', 'type': 'list', 'children': ['294', '299'], 'value': '[z[i-1],z[i]]'},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '-'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '298', 'type': 'integer', 'children': [], 'value': '1'},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '302', 'type': 'for_in_clause', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '305', 'type': 'else_clause', 'children': ['306']},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'lon'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '316', 'type': 'if_statement', 'children': ['317', '321']},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'tracks'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'binary_operator', 'children': ['329', '342', '343'], 'value': '+'},{'id': '329', 'type': 'list', 'children': ['330', '336'], 'value': '[np.array(lt),np.array(ln)]'},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'ln'},{'id': '342', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '343', 'type': 'list_comprehension', 'children': ['344', '350']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '350', 'type': 'for_in_clause', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'zz'},{'id': '353', 'type': 'return_statement', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'tracks'}
def split_tracks(lat,lon,*args): '''assumes eastward motion''' tracks = [] lt,ln = [lat[0]],[lon[0]] zz = [[z[0]] for z in args] for i in range(1,len(lon)): lt.append(lat[i]) for z,a in zip(zz,args): z.append(a[i]) d1 = abs(lon[i] - lon[i-1]) d2 = abs((lon[i-1] + 360) - lon[i]) d3 = abs(lon[i-1] - (lon[i] + 360)) if d2 < d1: ln.append(lon[i]-360) tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) lt = [lat[i-1],lat[i]] ln = [lon[i-1]+360,lon[i]] zz = [[z[i-1]] for z in args] elif d3 < d1: ln.append(lon[i]+360) tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) lt = [lat[i-1],lat[i]] ln = [lon[i-1]-360,lon[i]] zz = [[z[i-1],z[i]] for z in args] else: ln.append(lon[i]) if len(lt): tracks.append([np.array(lt),np.array(ln)] \ + [np.array(z) for z in zz]) return tracks
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_loaders'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '14', '30', '38', '48', '98', '125', '135', '155']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'matching_groups'},{'id': '12', 'type': 'list', 'children': ['13'], 'value': "['plaster.loader_factory']"},{'id': '13', 'type': 'string', 'children': [], 'value': "'plaster.loader_factory'"},{'id': '14', 'type': 'if_statement', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'augmented_assignment', 'children': ['19', '20'], 'value': '+='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'matching_groups'},{'id': '20', 'type': 'list_comprehension', 'children': ['21', '27']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "'plaster.{0}_loader_factory'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'proto'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'proto'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'if_statement', 'children': ['49', '55']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '54'], 'value': '=='},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '54', 'type': 'integer', 'children': [], 'value': '2'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'try_statement', 'children': ['57', '69', '75']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'distro'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'pkg_resources'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get_distribution'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'except_clause', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pkg_resources'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'DistributionNotFound'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'pass_statement', 'children': []},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77', '88']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_find_ep_in_dist'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '87']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'distro'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'matching_groups'},{'id': '88', 'type': 'if_statement', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'list', 'children': ['93'], 'value': '[EntryPointLoaderInfo(ep, protocols)]'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'EntryPointLoaderInfo'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'possible_entry_points'},{'id': '101', 'type': 'list_comprehension', 'children': ['102', '103', '111']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pkg_resources'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'iter_entry_points'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'plaster.loader_factory'"},{'id': '111', 'type': 'if_clause', 'children': ['112']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '116'], 'value': 'or'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'distros'},{'id': '128', 'type': 'set_comprehension', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'possible_entry_points'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'matched_entry_points'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'list_comprehension', 'children': ['146', '152']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_find_ep_in_dist'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'distro'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'matching_groups'},{'id': '152', 'type': 'for_in_clause', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'distro'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'distros'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'list_comprehension', 'children': ['157', '164']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'EntryPointLoaderInfo'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'protocols'},{'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'matched_entry_points'}
def find_loaders(scheme, protocols=None): matching_groups = ['plaster.loader_factory'] if protocols: matching_groups += [ 'plaster.{0}_loader_factory'.format(proto) for proto in protocols ] scheme = scheme.lower() parts = scheme.split('+', 1) if len(parts) == 2: try: distro = pkg_resources.get_distribution(parts[0]) except pkg_resources.DistributionNotFound: pass else: ep = _find_ep_in_dist(distro, parts[1], matching_groups) if ep: return [EntryPointLoaderInfo(ep, protocols)] possible_entry_points = [ ep for ep in pkg_resources.iter_entry_points('plaster.loader_factory') if scheme is None or scheme == ep.name.lower() ] distros = {ep.dist for ep in possible_entry_points} matched_entry_points = list(filter(None, [ _find_ep_in_dist(distro, scheme, matching_groups) for distro in distros ])) return [ EntryPointLoaderInfo(ep, protocols=protocols) for ep in matched_entry_points ]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_dicts'},{'id': '3', 'type': 'parameters', 'children': ['4', '6', '9']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '60']},{'id': '13', 'type': 'if_statement', 'children': ['14', '24', '35']},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '21'], 'value': 'and'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '20'], 'value': '=='},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37', '46']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '40', 'type': 'conditional_expression', 'children': ['41', '42', '45'], 'value': 'if'},{'id': '41', 'type': 'dictionary', 'children': []},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'conditional_expression', 'children': ['62', '80', '81'], 'value': 'if'},{'id': '62', 'type': 'dictionary_comprehension', 'children': ['63', '71']},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_copy'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cd'}
def combine_dicts(*dicts, copy=False, base=None): if len(dicts) == 1 and base is None: cd = dicts[0].copy() else: cd = {} if base is None else base for d in dicts: if d: cd.update(d) return {k: _copy.deepcopy(v) for k, v in cd.items()} if copy else cd
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'kk_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'adict'},{'id': '8', 'type': 'block', 'children': ['9', '62']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '44', '54']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '19', 'type': 'block', 'children': ['20', '37']},{'id': '20', 'type': 'if_statement', 'children': ['21', '31']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '29']},{'id': '23', 'type': 'attribute', 'children': ['24', '28']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isdisjoint'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'adict'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'keyword argument repeated'"},{'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': 'adict'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '44', 'type': 'elif_clause', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'adict'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'keyword argument repeated'"},{'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', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'adict'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'adict'}
def kk_dict(*kk, **adict): for k in kk: if isinstance(k, dict): if not set(k).isdisjoint(adict): raise ValueError('keyword argument repeated') adict.update(k) elif k in adict: raise ValueError('keyword argument repeated') else: adict[k] = k return adict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key_map'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '26', '32']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '17', 'type': 'call', 'children': ['18', '25']},{'id': '18', 'type': 'attribute', 'children': ['19', '24']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'combine_dicts'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'list_splat', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_map'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'combine_dicts'},{'id': '35', 'type': 'argument_list', 'children': ['36', '49', '52']},{'id': '36', 'type': 'dictionary_comprehension', 'children': ['37', '44']},{'id': '37', 'type': 'pair', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '48']},{'id': '45', 'type': 'pattern_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'base'}
def map_dict(key_map, *dicts, copy=False, base=None): it = combine_dicts(*dicts).items() get = key_map.get return combine_dicts({get(k, k): v for k, v in it}, copy=copy, base=base)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'key_map'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '23', '74']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '17', 'type': 'conditional_expression', 'children': ['18', '19', '22'], 'value': 'if'},{'id': '18', 'type': 'dictionary', 'children': []},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '32']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_map'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '39', '49', '66']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'map_dict'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'map_list'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '63']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '61', 'type': 'list_splat', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'd'},{'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', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'combine_dicts'},{'id': '77', 'type': 'argument_list', 'children': ['78', '81']},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'd'}
def map_list(key_map, *inputs, copy=False, base=None): d = {} if base is None else base for m, v in zip(key_map, inputs): if isinstance(m, dict): map_dict(m, v, base=d) elif isinstance(m, list): map_list(m, *v, base=d) else: d[m] = v return combine_dicts(copy=copy, base=d)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'selector'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '11', 'type': 'string', 'children': [], 'value': "'dict'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'allow_miss'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '38', '93']},{'id': '16', 'type': 'if_statement', 'children': ['17', '19', '27']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'allow_miss'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'function_definition', 'children': ['21', '22', '24']},{'id': '21', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '22', 'type': 'parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'function_definition', 'children': ['30', '31', '33']},{'id': '30', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '31', 'type': 'parameters', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42', '68']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '41', 'type': 'string', 'children': [], 'value': "'list'"},{'id': '42', 'type': 'block', 'children': ['43', '58']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '50', '53']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '53', 'type': 'if_clause', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'conditional_expression', 'children': ['60', '66', '67'], 'value': 'if'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_copy'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '68', 'type': 'elif_clause', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'output_type'},{'id': '71', 'type': 'string', 'children': [], 'value': "'values'"},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bypass'},{'id': '76', 'type': 'argument_list', 'children': ['77', '90']},{'id': '77', 'type': 'list_splat', 'children': ['78']},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '82', '85']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '85', 'type': 'if_clause', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bypass'},{'id': '96', 'type': 'argument_list', 'children': ['97', '111']},{'id': '97', 'type': 'dictionary_comprehension', 'children': ['98', '103', '106']},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '106', 'type': 'if_clause', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'copy'}
def selector(keys, dictionary, copy=False, output_type='dict', allow_miss=False): if not allow_miss: def check(key): return True else: def check(key): return key in dictionary if output_type == 'list': res = [dictionary[k] for k in keys if check(k)] return _copy.deepcopy(res) if copy else res elif output_type == 'values': return bypass(*[dictionary[k] for k in keys if check(k)], copy=copy) return bypass({k: dictionary[k] for k in keys if check(k)}, copy=copy)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'difference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10', '18', '24', '30', '92', '98']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__copy__'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '39']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '34', 'type': 'argument_list', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_as_multiset'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '49']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '54', 'type': 'block', 'children': ['55', '61', '67']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '-'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71', '82']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '>'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'block', 'children': ['72', '78']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'augmented_assignment', 'children': ['80', '81'], 'value': '-='},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '88']},{'id': '84', 'type': 'delete_statement', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '-='},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'result'}
def difference(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_multiset, others): for element, multiplicity in other.items(): if element in _elements: old_multiplicity = _elements[element] new_multiplicity = old_multiplicity - multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity else: del _elements[element] _total -= old_multiplicity result._total = _total return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10', '18', '24', '30', '77', '83']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__copy__'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '39']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '34', 'type': 'argument_list', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_as_mapping'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '49']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '60']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '>'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '64', 'type': 'block', 'children': ['65', '71']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'augmented_assignment', 'children': ['73', '74'], 'value': '+='},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '-'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'result'}
def union(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity result._total = _total return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersection'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10', '18', '24', '30', '95', '101']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__copy__'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '39']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '34', 'type': 'argument_list', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_as_mapping'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '52']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'block', 'children': ['53', '63']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'if_statement', 'children': ['69', '72', '85']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'block', 'children': ['73', '79']},{'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': '_elements'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '-='},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87', '91']},{'id': '87', 'type': 'delete_statement', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '-='},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'result'}
def intersection(self, *others): r result = self.__copy__() _elements = result._elements _total = result._total for other in map(self._as_mapping, others): for element, multiplicity in list(_elements.items()): new_multiplicity = other.get(element, 0) if new_multiplicity < multiplicity: if new_multiplicity > 0: _elements[element] = new_multiplicity _total -= multiplicity - new_multiplicity else: del _elements[element] _total -= multiplicity result._total = _total return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetric_difference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '9', '18', '26', '30', '36', '42', '48', '68', '121', '127']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_as_multiset'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': '__class__'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_total'},{'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': '_elements'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self_elements'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'other_elements'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dist_elements'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '60'], 'value': '|'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self_elements'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'other_elements'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dist_elements'},{'id': '71', 'type': 'block', 'children': ['72', '82', '92', '106', '110']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self_elements'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'other_multiplicity'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'other_elements'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'conditional_expression', 'children': ['97', '100', '103'], 'value': 'if'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '-'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'other_multiplicity'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '>'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'other_multiplicity'},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '-'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'other_multiplicity'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'augmented_assignment', 'children': ['108', '109'], 'value': '+='},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '>'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'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': '_elements'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'new_multiplicity'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'result'}
def symmetric_difference(self, other): r other = self._as_multiset(other) result = self.__class__() _total = 0 _elements = result._elements self_elements = self._elements other_elements = other._elements dist_elements = set(self_elements.keys()) | set(other_elements.keys()) for element in dist_elements: multiplicity = self_elements.get(element, 0) other_multiplicity = other_elements.get(element, 0) new_multiplicity = (multiplicity - other_multiplicity if multiplicity > other_multiplicity else other_multiplicity - multiplicity) _total += new_multiplicity if new_multiplicity > 0: _elements[element] = new_multiplicity result._total = _total return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'times'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '6', 'type': 'block', 'children': ['7', '18', '28', '36', '42', '52', '58']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '<'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'The factor must no be negative.'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': '__copy__'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '51'], 'value': '*='},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '57'], 'value': '*='},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'result'}
def times(self, factor): if factor == 0: return self.__class__() if factor < 0: raise ValueError('The factor must no be negative.') result = self.__copy__() _elements = result._elements for element in _elements: _elements[element] *= factor result._total *= factor return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'union_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10', '16', '22', '69']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '31']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_as_mapping'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'for_statement', 'children': ['33', '36', '41']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '52']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '>'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '56', 'type': 'block', 'children': ['57', '63']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'augmented_assignment', 'children': ['65', '66'], 'value': '+='},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '-'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_total'}
def union_update(self, *others): r _elements = self._elements _total = self._total for other in map(self._as_mapping, others): for element, multiplicity in other.items(): old_multiplicity = _elements.get(element, 0) if multiplicity > old_multiplicity: _elements[element] = multiplicity _total += multiplicity - old_multiplicity self._total = _total
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersection_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '19']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_as_mapping'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'for_statement', 'children': ['21', '24', '32']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'current_count'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '26', 'type': 'argument_list', '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': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '43']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '<'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'current_count'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'multiplicity'}
def intersection_update(self, *others): r for other in map(self._as_mapping, others): for element, current_count in list(self.items()): multiplicity = other.get(element, 0) if multiplicity < current_count: self[element] = multiplicity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'difference_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '7', 'type': 'block', 'children': ['8', '10']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '19']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_as_multiset'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'for_statement', 'children': ['21', '24', '29']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'multiplicity'}
def difference_update(self, *others): r for other in map(self._as_multiset, others): for element, multiplicity in other.items(): self.discard(element, multiplicity)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetric_difference_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '9', '18', '38']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_as_multiset'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '21', 'type': 'binary_operator', 'children': ['22', '30'], 'value': '|'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'distinct_elements'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'distinct_elements'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '41', 'type': 'block', 'children': ['42', '48', '54']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'other_count'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'conditional_expression', 'children': ['61', '64', '67'], 'value': 'if'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '-'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'other_count'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '>'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'other_count'},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '-'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'other_count'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'multiplicity'}
def symmetric_difference_update(self, other): r other = self._as_multiset(other) elements = set(self.distinct_elements()) | set(other.distinct_elements()) for element in elements: multiplicity = self[element] other_count = other[element] self[element] = (multiplicity - other_count if multiplicity > other_count else other_count - multiplicity)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'times_update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11', '17', '28']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '<'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'raise_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"The factor must not be negative."'},{'id': '17', 'type': 'elif_clause', 'children': ['18', '21']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30', '36', '46']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'augmented_assignment', 'children': ['42', '45'], 'value': '*='},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '51'], 'value': '*='},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'factor'}
def times_update(self, factor): if factor < 0: raise ValueError("The factor must not be negative.") elif factor == 0: self.clear() else: _elements = self._elements for element in _elements: _elements[element] *= factor self._total *= factor
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'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': 'element'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'block', 'children': ['10', '20', '28']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '<'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'raise_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"Multiplicity must be positive"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'augmented_assignment', 'children': ['22', '27'], 'value': '+='},{'id': '22', 'type': 'subscript', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'augmented_assignment', 'children': ['30', '33'], 'value': '+='},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'multiplicity'}
def add(self, element, multiplicity=1): if multiplicity < 1: raise ValueError("Multiplicity must be positive") self._elements[element] += multiplicity self._total += multiplicity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16', '23', '33', '79']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'not'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'if_statement', 'children': ['34', '41', '52', '62']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '38'], 'value': 'or'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '>='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '41', 'type': 'block', 'children': ['42', '46']},{'id': '42', 'type': 'delete_statement', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '51'], 'value': '-='},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '52', 'type': 'elif_clause', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"Multiplicity must be not be negative"'},{'id': '62', 'type': 'elif_clause', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'block', 'children': ['67', '73']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'augmented_assignment', 'children': ['69', '72'], 'value': '-='},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'augmented_assignment', 'children': ['75', '78'], 'value': '-='},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'}
def remove(self, element, multiplicity=None): _elements = self._elements if element not in _elements: raise KeyError old_multiplicity = _elements.get(element, 0) if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must be not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'discard'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '75']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '20', 'type': 'block', 'children': ['21', '27', '73']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '27', 'type': 'if_statement', 'children': ['28', '35', '46', '56']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'or'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '>='},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '35', 'type': 'block', 'children': ['36', '40']},{'id': '36', 'type': 'delete_statement', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'augmented_assignment', 'children': ['42', '45'], 'value': '-='},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '46', 'type': 'elif_clause', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'raise_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '"Multiplicity must not be negative"'},{'id': '56', 'type': 'elif_clause', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '>'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'block', 'children': ['61', '67']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '66'], 'value': '-='},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'augmented_assignment', 'children': ['69', '72'], 'value': '-='},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_total'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'multiplicity'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'old_multiplicity'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'}
def discard(self, element, multiplicity=None): _elements = self._elements if element in _elements: old_multiplicity = _elements[element] if multiplicity is None or multiplicity >= old_multiplicity: del _elements[element] self._total -= old_multiplicity elif multiplicity < 0: raise ValueError("Multiplicity must not be negative") elif multiplicity > 0: _elements[element] -= multiplicity self._total -= multiplicity return old_multiplicity else: return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'async_thread'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '8', 'type': 'list_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '12', 'type': 'block', 'children': ['13', '32', '49', '53', '79', '85', '99', '118', '206', '216', '229', '242']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_get_executor'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_executor_name'},{'id': '21', 'type': 'argument_list', 'children': ['22', '29']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'executor'"},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dsp'},{'id': '32', 'type': 'if_statement', 'children': ['33', '35']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_evaluate_node'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44', '45', '47']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '45', 'type': 'list_splat', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '47', 'type': 'dictionary_splat', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '53', 'type': 'if_statement', 'children': ['54', '68']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '60'], 'value': 'and'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': '=='},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '58', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '60', 'type': '()', 'children': ['61']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'or'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '64', 'type': 'string', 'children': [], 'value': "'wait_inputs'"},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'import_from_statement', 'children': ['80', '83']},{'id': '80', 'type': 'dotted_name', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'concurrent'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '83', 'type': 'dotted_name', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '88', 'type': 'set_comprehension', 'children': ['89', '90', '93']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '93', 'type': 'if_clause', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '99', 'type': 'function_definition', 'children': ['100', '101', '102']},{'id': '100', 'type': 'function_name', 'children': [], 'value': '_submit'},{'id': '101', 'type': 'parameters', 'children': []},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110', '111', '112', '113', '114', '116']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_async_eval'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '114', 'type': 'list_splat', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '116', 'type': 'dictionary_splat', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120', '198']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '120', 'type': 'block', 'children': ['121', '127', '158', '184']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'function_definition', 'children': ['128', '129', '131']},{'id': '128', 'type': 'function_name', 'children': [], 'value': '_set_res'},{'id': '129', 'type': 'parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'try_statement', 'children': ['133', '145']},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'set_result'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'except_clause', 'children': ['146', '150']},{'id': '146', 'type': 'as_pattern', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'BaseException'},{'id': '148', 'type': 'as_pattern_target', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'set_exception'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '158', 'type': 'function_definition', 'children': ['159', '160', '164']},{'id': '159', 'type': 'function_name', 'children': [], 'value': '_submit_task'},{'id': '160', 'type': 'parameters', 'children': ['161']},{'id': '161', 'type': 'default_parameter', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '163', 'type': 'None', 'children': []},{'id': '164', 'type': 'block', 'children': ['165', '172']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'discard'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '176'], 'value': 'and'},{'id': '174', 'type': 'not_operator', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_submit'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'add_done_callback'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_set_res'},{'id': '184', 'type': 'for_statement', 'children': ['185', '186', '190']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '190', 'type': 'block', 'children': ['191']},{'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': 'f'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'add_done_callback'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_submit_task'},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_submit'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'await_result'"},{'id': '215', 'type': 'False', 'children': []},{'id': '216', 'type': 'if_statement', 'children': ['217', '220']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'is'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '219', 'type': 'False', 'children': []},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'return_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': '_await_result'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226', '227', '228']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': "'outputs'"},{'id': '241', 'type': 'list', 'children': [], 'value': '[]'},{'id': '242', 'type': 'return_statement', 'children': ['243']},{'id': '243', 'type': 'conditional_expression', 'children': ['244', '253', '256'], 'value': 'if'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'AsyncList'},{'id': '246', 'type': 'argument_list', 'children': ['247', '250']},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': '>'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '255', 'type': 'integer', 'children': [], 'value': '1'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'result'}
def async_thread(sol, args, node_attr, node_id, *a, **kw): executor = _get_executor(_executor_name(kw.get('executor', False), sol.dsp)) if not executor: return sol._evaluate_node(args, node_attr, node_id, *a, **kw) futures = args if node_attr['type'] == 'data' and ( node_attr['wait_inputs'] or 'function' in node_attr): futures = args[0].values() from concurrent.futures import Future futures = {v for v in futures if isinstance(v, Future)} def _submit(): return executor.thread( _async_eval, sol, args, node_attr, node_id, *a, **kw ) if futures: result = Future() def _set_res(fut): try: result.set_result(fut.result()) except BaseException as ex: result.set_exception(ex) def _submit_task(fut=None): futures.discard(fut) not futures and _submit().add_done_callback(_set_res) for f in list(futures): f.add_done_callback(_submit_task) else: result = _submit() timeout = node_attr.get('await_result', False) if timeout is not False: return _await_result(result, timeout, sol, node_id) n = len(node_attr.get('outputs', [])) return AsyncList(future=result, n=n) if n > 1 else result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pivot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '8', 'type': 'block', 'children': ['9', '13', '17', '21', '115', '155', '162', '169', '173', '230']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ysort'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '24', 'type': 'block', 'children': ['25', '38', '50', '63', '75', '90', '105']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ysort'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ysort'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'list_comprehension', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '75', 'type': 'try_statement', 'children': ['76', '81']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '81', 'type': 'except_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '89', 'type': 'dictionary', 'children': []},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '104']},{'id': '99', 'type': 'subscript', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'augmented_assignment', 'children': ['107', '112'], 'value': '+='},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '131']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '127'], 'value': '-'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'if_statement', 'children': ['137', '146']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'not'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '154']},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '154', 'type': 'string', 'children': [], 'value': "''"},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'headings'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'headings'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'xsort'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '172', 'type': 'list', 'children': [], 'value': '[]'},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ysort'},{'id': '176', 'type': 'block', 'children': ['177', '184', '197', '209', '216']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sortedkeys'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '196']},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sortedvalues'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '202', 'type': 'argument_list', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sortedkeys'},{'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': 'row'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'sortedvalues'},{'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': 't'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'headings'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 't'}
def pivot(table, left, top, value): rs = {} ysort = [] xsort = [] for row in table: yaxis = tuple([row[c] for c in left]) if yaxis not in ysort: ysort.append(yaxis) xaxis = tuple([row[c] for c in top]) if xaxis not in xsort: xsort.append(xaxis) try: rs[yaxis] except KeyError: rs[yaxis] = {} if xaxis not in rs[yaxis]: rs[yaxis][xaxis] = 0 rs[yaxis][xaxis] += row[value] for key in rs: if len(rs[key]) - len(xsort): for var in xsort: if var not in rs[key].keys(): rs[key][var] = '' headings = list(left) headings.extend(xsort) t = [] for left in ysort: row = list(left) sortedkeys = sorted(rs[left].keys()) sortedvalues = map(rs[left].get, sortedkeys) row.extend(sortedvalues) t.append(dict(zip(headings,row))) return t
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download_hrrr_for_gssha'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'main_directory'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'forecast_start_date_string'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'forecast_start_hour_string'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'leftlon'},{'id': '9', 'type': 'unary_operator', 'children': ['10'], 'value': '-'},{'id': '10', 'type': 'integer', 'children': [], 'value': '180'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rightlon'},{'id': '13', 'type': 'integer', 'children': [], 'value': '180'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'toplat'},{'id': '16', 'type': 'integer', 'children': [], 'value': '90'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'bottomlat'},{'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '-'},{'id': '20', 'type': 'integer', 'children': [], 'value': '90'},{'id': '21', 'type': 'block', 'children': ['22', '32', '43', '66', '70', '269']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'out_directory'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'main_directory'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'forecast_start_date_string'},{'id': '32', 'type': 'try_statement', 'children': ['33', '39']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mkdir'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'out_directory'},{'id': '39', 'type': 'except_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'pass_statement', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'forecast_timestep_hour_string_array'},{'id': '46', 'type': 'list', 'children': ['47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65'], 'value': "['00', '01', '02', '03', '04',\n '05', '06', '07', '08', '09',\n '10', '11', '12', '13', '14',\n '15', '16', '17', '18']"},{'id': '47', 'type': 'string', 'children': [], 'value': "'00'"},{'id': '48', 'type': 'string', 'children': [], 'value': "'01'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'02'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'03'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'04'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'05'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'06'"},{'id': '54', 'type': 'string', 'children': [], 'value': "'07'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'08'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'09'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'10'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'11'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'12'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'13'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'14'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'15'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'16'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'17'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'18'"},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'downloaded_file_list'},{'id': '69', 'type': 'list', 'children': [], 'value': '[]'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'forecast_timestep_hour_string'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'forecast_timestep_hour_string_array'},{'id': '73', 'type': 'block', 'children': ['74', '84', '162', '177']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'hrrr.t{0}z.wrfsfcf{1}.grib2'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'forecast_start_hour_string'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'forecast_timestep_hour_string'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '87', 'type': 'dictionary', 'children': ['88', '91', '94', '97', '100', '103', '106', '109', '112', '115', '118', '121', '124', '127', '130', '136', '142', '148', '154']},{'id': '88', 'type': 'pair', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '91', 'type': 'pair', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': "'lev_10_m_above_ground'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'lev_2_m_above_ground'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '97', 'type': 'pair', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'lev_entire_atmosphere'"},{'id': '99', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '100', 'type': 'pair', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'lev_surface'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '103', 'type': 'pair', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': "'var_DSWRF'"},{'id': '105', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '106', 'type': 'pair', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'var_PRATE'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '109', 'type': 'pair', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'var_PRES'"},{'id': '111', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '112', 'type': 'pair', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': "'var_RH'"},{'id': '114', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '115', 'type': 'pair', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'var_TMP'"},{'id': '117', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'var_UGRD'"},{'id': '120', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'var_VGRD'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '124', 'type': 'pair', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'var_TCDC'"},{'id': '126', 'type': 'string', 'children': [], 'value': "'on'"},{'id': '127', 'type': 'pair', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': "'subregion'"},{'id': '129', 'type': 'string', 'children': [], 'value': "''"},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'leftlon'"},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'leftlon'},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'rightlon'"},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'rightlon'},{'id': '142', 'type': 'pair', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'toplat'"},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'toplat'},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "'bottomlat'"},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'bottomlat'},{'id': '154', 'type': 'pair', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'dir'"},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'/hrrr.{0}'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'forecast_start_date_string'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '174']},{'id': '170', 'type': 'string', 'children': [], 'value': "'http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl'"},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '187', '235']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '182'], 'value': '=='},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '182', 'type': 'attribute', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '187', 'type': 'block', 'children': ['188', '198', '205']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'out_directory'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'downloaded_file_list'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '205', 'type': 'with_statement', 'children': ['206', '216']},{'id': '206', 'type': 'with_clause', 'children': ['207']},{'id': '207', 'type': 'with_item', 'children': ['208']},{'id': '208', 'type': 'as_pattern', 'children': ['209', '214']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'out_file'},{'id': '213', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '214', 'type': 'as_pattern_target', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'for_statement', 'children': ['218', '219', '227']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '235', 'type': 'else_clause', 'children': ['236']},{'id': '236', 'type': 'block', 'children': ['237', '249', '264', '268']},{'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': 'log'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'string', 'children': [], 'value': '"Problem downloading {0}"'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '249', 'type': 'for_statement', 'children': ['250', '251', '252']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'downloaded_file_list'},{'id': '252', 'type': 'block', 'children': ['253']},{'id': '253', 'type': 'try_statement', 'children': ['254', '260']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '260', 'type': 'except_clause', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'pass_statement', 'children': []},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'downloaded_file_list'},{'id': '267', 'type': 'list', 'children': [], 'value': '[]'},{'id': '268', 'type': 'break_statement', 'children': []},{'id': '269', 'type': 'return_statement', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'downloaded_file_list'}
def download_hrrr_for_gssha(main_directory, forecast_start_date_string, forecast_start_hour_string, leftlon=-180, rightlon=180, toplat=90,bottomlat=-90): out_directory = path.join(main_directory, forecast_start_date_string) try: mkdir(out_directory) except OSError: pass forecast_timestep_hour_string_array = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18'] downloaded_file_list = [] for forecast_timestep_hour_string in forecast_timestep_hour_string_array: file_name = 'hrrr.t{0}z.wrfsfcf{1}.grib2'.format(forecast_start_hour_string, forecast_timestep_hour_string) payload = { 'file': file_name, 'lev_10_m_above_ground': 'on', 'lev_2_m_above_ground': 'on', 'lev_entire_atmosphere': 'on', 'lev_surface': 'on', 'var_DSWRF': 'on', 'var_PRATE': 'on', 'var_PRES': 'on', 'var_RH': 'on', 'var_TMP': 'on', 'var_UGRD': 'on', 'var_VGRD': 'on', 'var_TCDC': 'on', 'subregion': '', 'leftlon': str(leftlon), 'rightlon': str(rightlon), 'toplat': str(toplat), 'bottomlat': str(bottomlat), 'dir': '/hrrr.{0}'.format(forecast_start_date_string), } r = requests.get('http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl', params=payload, stream=True) if r.status_code == requests.codes.ok: out_file = path.join(out_directory, file_name) downloaded_file_list.append(out_file) with open(out_file, 'wb') as fd: for chunk in r.iter_content(chunk_size=1024): fd.write(chunk) else: log.error("Problem downloading {0}".format(file_name)) for filename in downloaded_file_list: try: remove(filename) except OSError: pass downloaded_file_list = [] break return downloaded_file_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_convert_data_to_hourly'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '6', 'type': 'block', 'children': ['7', '30', '39', '43', '392']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'time_step_hours'},{'id': '10', 'type': 'binary_operator', 'children': ['11', '23'], 'value': '/'},{'id': '11', 'type': 'subscript', 'children': ['12', '22']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'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': 'data'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'timedelta64'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'string', 'children': [], 'value': "'h'"},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'calc_function'},{'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': '_get_calc_function'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '47', '68']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '<'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'time_step_hours'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'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': 'data'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'resample'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '62', '65']},{'id': '58', 'type': 'string', 'children': [], 'value': "'1H'"},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '61', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'how'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'calc_function'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'keep_attrs'},{'id': '67', 'type': 'True', 'children': []},{'id': '68', 'type': 'elif_clause', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'time_step_hours'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'block', 'children': ['73', '90']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'resample'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '87']},{'id': '83', 'type': 'string', 'children': [], 'value': "'1H'"},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '86', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'keep_attrs'},{'id': '89', 'type': 'True', 'children': []},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '102']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'time_idx'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'subscript', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '101', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '115', '280']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '<'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'time_idx'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'subscript', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '114', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '115', 'type': 'block', 'children': ['116', '128', '142', '156', '173', '189', '213', '243', '254']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '119', 'type': 'attribute', 'children': ['120', '127']},{'id': '120', 'type': 'subscript', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'time_idx'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '131', 'type': 'attribute', 'children': ['132', '141']},{'id': '132', 'type': 'subscript', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'time_idx'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'slope_timeslice'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '147', 'type': 'argument_list', 'children': ['148', '152']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '172'], 'value': '-'},{'id': '160', 'type': 'subscript', 'children': ['161', '171']},{'id': '161', 'type': 'attribute', 'children': ['162', '170']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'slope_timeslice'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '171', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'first_timestep'},{'id': '176', 'type': 'subscript', 'children': ['177', '188']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'slope'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '209'], 'value': '/'},{'id': '193', 'type': '()', 'children': ['194']},{'id': '194', 'type': 'binary_operator', 'children': ['195', '208'], 'value': '-'},{'id': '195', 'type': 'subscript', 'children': ['196', '207']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'first_timestep'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'data_timeslice'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '218', 'type': 'argument_list', 'children': ['219', '231']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '+'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'timedelta64'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230']},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '-'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'timedelta64'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242']},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'data_timeslice'},{'id': '254', 'type': 'for_statement', 'children': ['255', '256', '264']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'xidx'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'subscript', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '263', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '272']},{'id': '267', 'type': 'subscript', 'children': ['268', '271']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'xidx'},{'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '+'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'first_timestep'},{'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '*'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'slope'},{'id': '276', 'type': '()', 'children': ['277']},{'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '+'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'xidx'},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282', '294', '305']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '285', 'type': 'attribute', 'children': ['286', '293']},{'id': '286', 'type': 'subscript', 'children': ['287', '292']},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'time_idx'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '297', 'type': 'attribute', 'children': ['298', '304']},{'id': '298', 'type': 'subscript', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '302', 'type': 'unary_operator', 'children': ['303'], 'value': '-'},{'id': '303', 'type': 'integer', 'children': [], 'value': '1'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '305', 'type': 'if_statement', 'children': ['306', '309']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': '>'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '309', 'type': 'block', 'children': ['310', '326', '340', '351', '355', '368']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'first_timestep'},{'id': '313', 'type': 'subscript', 'children': ['314', '325']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'data_timeslice'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '331', 'type': 'argument_list', 'children': ['332', '336']},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'sel'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'data_timeslice'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '354', 'type': 'integer', 'children': [], 'value': '1'},{'id': '355', 'type': 'if_statement', 'children': ['356', '359']},{'id': '356', 'type': 'comparison_operator', 'children': ['357', '358'], 'value': '=='},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'calc_function'},{'id': '358', 'type': 'string', 'children': [], 'value': '"mean"'},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'assignment', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '363', 'type': 'subscript', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '367', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '368', 'type': 'for_statement', 'children': ['369', '370', '378']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'xidx'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'subscript', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '377', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '378', 'type': 'block', 'children': ['379']},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'assignment', 'children': ['381', '386']},{'id': '381', 'type': 'subscript', 'children': ['382', '385']},{'id': '382', 'type': 'subscript', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'data_subset'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'gssha_data_var'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'xidx'},{'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '/'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'first_timestep'},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'slice_size'},{'id': '392', 'type': 'if_statement', 'children': ['393', '396']},{'id': '393', 'type': 'comparison_operator', 'children': ['394', '395'], 'value': 'is'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '395', 'type': 'None', 'children': []},{'id': '396', 'type': 'block', 'children': ['397', '436', '475']},{'id': '397', 'type': 'if_statement', 'children': ['398', '409']},{'id': '398', 'type': 'comparison_operator', 'children': ['399', '406'], 'value': 'not'},{'id': '399', 'type': 'attribute', 'children': ['400', '405']},{'id': '400', 'type': 'attribute', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'x_var'},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '409', 'type': 'block', 'children': ['410']},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'assignment', 'children': ['412', '423']},{'id': '412', 'type': 'subscript', 'children': ['413', '416']},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '416', 'type': 'attribute', 'children': ['417', '422']},{'id': '417', 'type': 'attribute', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'x_var'},{'id': '423', 'type': 'subscript', 'children': ['424', '429']},{'id': '424', 'type': 'attribute', 'children': ['425', '428']},{'id': '425', 'type': 'attribute', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '429', 'type': 'attribute', 'children': ['430', '435']},{'id': '430', 'type': 'attribute', 'children': ['431', '434']},{'id': '431', 'type': 'attribute', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'x_var'},{'id': '436', 'type': 'if_statement', 'children': ['437', '448']},{'id': '437', 'type': 'comparison_operator', 'children': ['438', '445'], 'value': 'not'},{'id': '438', 'type': 'attribute', 'children': ['439', '444']},{'id': '439', 'type': 'attribute', 'children': ['440', '443']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'y_var'},{'id': '445', 'type': 'attribute', 'children': ['446', '447']},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '448', 'type': 'block', 'children': ['449']},{'id': '449', 'type': 'expression_statement', 'children': ['450']},{'id': '450', 'type': 'assignment', 'children': ['451', '462']},{'id': '451', 'type': 'subscript', 'children': ['452', '455']},{'id': '452', 'type': 'attribute', 'children': ['453', '454']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'resampled_data'},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '455', 'type': 'attribute', 'children': ['456', '461']},{'id': '456', 'type': 'attribute', 'children': ['457', '460']},{'id': '457', 'type': 'attribute', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'y_var'},{'id': '462', 'type': 'subscript', 'children': ['463', '468']},{'id': '463', 'type': 'attribute', 'children': ['464', '467']},{'id': '464', 'type': 'attribute', 'children': ['465', '466']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '468', 'type': 'attribute', 'children': ['469', '474']},{'id': '469', 'type': 'attribute', 'children': ['470', '473']},{'id': '470', 'type': 'attribute', 'children': ['471', '472']},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'lsm'},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'y_var'},{'id': '475', 'type': 'expression_statement', 'children': ['476']},{'id': '476', 'type': 'assignment', 'children': ['477', '480']},{'id': '477', 'type': 'attribute', 'children': ['478', '479']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'resampled_data'}
def _convert_data_to_hourly(self, gssha_data_var): time_step_hours = np.diff(self.data.time)[0]/np.timedelta64(1, 'h') calc_function = self._get_calc_function(gssha_data_var) resampled_data = None if time_step_hours < 1: resampled_data = self.data.resample('1H', dim='time', how=calc_function, keep_attrs=True) elif time_step_hours > 1: resampled_data = self.data.resample('1H', dim='time', keep_attrs=True) for time_idx in range(self.data.dims['time']): if time_idx+1 < self.data.dims['time']: start_time = self.data.time[time_idx].values end_time = self.data.time[time_idx+1].values slope_timeslice = slice(str(start_time), str(end_time)) slice_size = resampled_data.sel(time=slope_timeslice).dims['time'] - 1 first_timestep = resampled_data.sel(time=str(start_time))[gssha_data_var] slope = (resampled_data.sel(time=str(end_time))[gssha_data_var] - first_timestep)/float(slice_size) data_timeslice = slice(str(start_time+np.timedelta64(1, 'm')), str(end_time-np.timedelta64(1, 'm'))) data_subset = resampled_data.sel(time=data_timeslice) for xidx in range(data_subset.dims['time']): data_subset[gssha_data_var][xidx] = first_timestep + slope * (xidx+1) else: start_time = self.data.time[time_idx].values end_time = resampled_data.time[-1].values if end_time > start_time: first_timestep = resampled_data.sel(time=str(start_time))[gssha_data_var] data_timeslice = slice(str(start_time), str(end_time)) data_subset = resampled_data.sel(time=data_timeslice) slice_size = 1 if calc_function == "mean": slice_size = data_subset.dims['time'] for xidx in range(data_subset.dims['time']): data_subset[gssha_data_var][xidx] = first_timestep/float(slice_size) if resampled_data is not None: if self.data.lsm.x_var not in resampled_data.coords: resampled_data.coords[self.data.lsm.x_var] = self.data.coords[self.data.lsm.x_var] if self.data.lsm.y_var not in resampled_data.coords: resampled_data.coords[self.data.lsm.y_var] = self.data.coords[self.data.lsm.y_var] self.data = resampled_data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sub_dsp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'edges_bunch'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '27', '49', '63', '77', '85', '122', '137', '173', '178', '195', '213']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '13', 'type': 'list_comprehension', 'children': ['14', '24']},{'id': '14', 'type': 'subscript', 'children': ['15', '23']},{'id': '15', 'type': 'subscript', 'children': ['16', '22']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_node'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'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': 'copy_structure'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '37', 'type': 'call', 'children': ['38', '48']},{'id': '38', 'type': 'attribute', 'children': ['39', '47']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'subgraph'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dmap_out_degree'},{'id': '54', 'type': 'expression_list', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dmap_dv'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'dmap_rm_edge'},{'id': '68', 'type': 'expression_list', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'remove_edge'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dmap_rm_node'},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '88', 'type': 'block', 'children': ['89', '101']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '92', 'type': 'call', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'inputs'"},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '116']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '106'], 'value': 'and'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'not_operator', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '114']},{'id': '108', 'type': 'attribute', 'children': ['109', '113']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'nodes_bunch'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dmap_rm_node'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '122', 'type': 'if_statement', 'children': ['123', '126']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'is'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'edges_bunch'},{'id': '125', 'type': 'None', 'children': []},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'edges_bunch'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'dmap_rm_edge'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'list_splat', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '160']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '139', 'type': 'list_comprehension', 'children': ['140', '141', '154']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '145']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '145', 'type': 'call', 'children': ['146', '153']},{'id': '146', 'type': 'attribute', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'if_clause', 'children': ['155']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '159'], 'value': '=='},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '158', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '159', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'if_statement', 'children': ['162', '167']},{'id': '162', 'type': 'not_operator', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'dmap_out_degree'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dmap_rm_node'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '173', 'type': 'import_from_statement', 'children': ['174', '176']},{'id': '174', 'type': 'dotted_name', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '176', 'type': 'dotted_name', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'isolates'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'remove_nodes_from'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'isolates'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '200', 'type': 'dictionary_comprehension', 'children': ['201', '206', '209']},{'id': '201', 'type': 'pair', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'dmap_dv'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '206', 'type': 'for_in_clause', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'dmap_dv'},{'id': '209', 'type': 'if_clause', 'children': ['210']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'in'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '213', 'type': 'return_statement', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sub_dsp'}
def get_sub_dsp(self, nodes_bunch, edges_bunch=None): nodes_bunch = [self.get_node(u)[1][0] for u in nodes_bunch] sub_dsp = self.copy_structure( dmap=self.dmap.subgraph(nodes_bunch).copy() ) nodes, dmap_out_degree = sub_dsp.nodes, sub_dsp.dmap.out_degree dmap_dv, dmap_rm_edge = self.default_values, sub_dsp.dmap.remove_edge dmap_rm_node = sub_dsp.dmap.remove_node for u in nodes_bunch: n = nodes[u].get('inputs', None) if n is not None and not set(n).issubset(nodes_bunch): dmap_rm_node(u) if edges_bunch is not None: for e in edges_bunch: dmap_rm_edge(*e) for u in [u for u, n in sub_dsp.dmap.nodes.items() if n['type'] == 'function']: if not dmap_out_degree(u): dmap_rm_node(u) from networkx import isolates sub_dsp.dmap.remove_nodes_from(list(isolates(sub_dsp.dmap))) sub_dsp.default_values = {k: dmap_dv[k] for k in dmap_dv if k in nodes} return sub_dsp
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'blue'},{'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': 'memo'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '27', '35', '45', '75', '81', '90', '106', '144', '301']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '14', '17'], 'value': 'if'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'import_from_statement', 'children': ['28', '33']},{'id': '28', 'type': 'relative_import', 'children': ['29', '30']},{'id': '29', 'type': 'import_prefix', 'children': []},{'id': '30', 'type': 'dotted_name', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dsp'},{'id': '33', 'type': 'dotted_name', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'map_list'},{'id': '35', 'type': 'import_from_statement', 'children': ['36', '41', '43']},{'id': '36', 'type': 'relative_import', 'children': ['37', '38']},{'id': '37', 'type': 'import_prefix', 'children': []},{'id': '38', 'type': 'dotted_name', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'blue'},{'id': '41', 'type': 'dotted_name', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'BlueDispatcher'},{'id': '43', 'type': 'dotted_name', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_parent_blue'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'blue'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'BlueDispatcher'},{'id': '54', 'type': 'argument_list', 'children': ['55', '60', '65', '70']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'raises'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'raises'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dfl'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key_map_data'},{'id': '84', 'type': 'list', 'children': ['85', '86'], 'value': "['data_id', {'value': 'default_value'}]"},{'id': '85', 'type': 'string', 'children': [], 'value': "'data_id'"},{'id': '86', 'type': 'dictionary', 'children': ['87']},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'default_value'"},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'succ'},{'id': '95', 'type': 'expression_list', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'dmap'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'succ'},{'id': '106', 'type': 'function_definition', 'children': ['107', '108', '112']},{'id': '107', 'type': 'function_name', 'children': [], 'value': '_set_weight'},{'id': '108', 'type': 'parameters', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '112', 'type': 'block', 'children': ['113', '135']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '116', 'type': 'dictionary_comprehension', 'children': ['117', '122', '131']},{'id': '117', 'type': 'pair', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '121', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '122', 'type': 'for_in_clause', 'children': ['123', '126']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'if_clause', 'children': ['132']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': 'in'},{'id': '133', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '144', 'type': 'for_statement', 'children': ['145', '148', '168']},{'id': '145', 'type': 'pattern_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '150', 'type': 'argument_list', 'children': ['151', '158']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '157', 'type': 'argument_list', 'children': []},{'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': 'x'},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '168', 'type': 'block', 'children': ['169', '177', '186', '190', '290']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '186', 'type': 'delete_statement', 'children': ['187']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '189', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '190', 'type': 'if_statement', 'children': ['191', '194', '218']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '=='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '193', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '194', 'type': 'block', 'children': ['195', '199']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '198', 'type': 'string', 'children': [], 'value': "'add_data'"},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'combine_dicts'},{'id': '202', 'type': 'argument_list', 'children': ['203', '215']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'map_list'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'key_map_data'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dfl'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '214', 'type': 'dictionary', 'children': []},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '218', 'type': 'elif_clause', 'children': ['219', '224']},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'in'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '221', 'type': 'tuple', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '223', 'type': 'string', 'children': [], 'value': "'dispatcher'"},{'id': '224', 'type': 'block', 'children': ['225', '231', '240', '248', '252', '261', '270']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '%'},{'id': '229', 'type': 'string', 'children': [], 'value': "'add_%s'"},{'id': '230', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '231', 'type': 'if_statement', 'children': ['232', '235']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': '=='},{'id': '233', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '234', 'type': 'string', 'children': [], 'value': "'dispatcher'"},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '239', 'type': 'string', 'children': [], 'value': "'dsp'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '247']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '%'},{'id': '245', 'type': 'string', 'children': [], 'value': "'%s_id'"},{'id': '246', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '248', 'type': 'delete_statement', 'children': ['249']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '251', 'type': 'string', 'children': [], 'value': "'wait_inputs'"},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': '_set_weight'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258']},{'id': '256', 'type': 'string', 'children': [], 'value': "'inp_weight'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_set_weight'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266', '267']},{'id': '265', 'type': 'string', 'children': [], 'value': "'out_weight'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'succ'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '270', 'type': 'if_statement', 'children': ['271', '274']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': 'in'},{'id': '272', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '280']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': '_parent_blue'},{'id': '282', 'type': 'argument_list', 'children': ['283', '289']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'memo'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'blue'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'deferred'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'tuple', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'blue'}
def blue(self, memo=None): memo = {} if memo is None else memo if self in memo: return memo[self] from .utils.dsp import map_list from .utils.blue import BlueDispatcher, _parent_blue memo[self] = blue = BlueDispatcher( executor=self.executor, name=self.name, raises=self.raises, description=self.__doc__ ) dfl = self.default_values key_map_data = ['data_id', {'value': 'default_value'}] pred, succ = self.dmap.pred, self.dmap.succ def _set_weight(n, r, d): d = {i: j['weight'] for i, j in d.items() if 'weight' in j} if d: r[n] = d for k, v in sorted(self.nodes.items(), key=lambda x: x[1]['index']): v = v.copy() t = v.pop('type') del v['index'] if t == 'data': method = 'add_data' combine_dicts(map_list(key_map_data, k, dfl.get(k, {})), base=v) elif t in ('function', 'dispatcher'): method = 'add_%s' % t if t == 'dispatcher': t = 'dsp' v['%s_id' % t] = k del v['wait_inputs'] _set_weight('inp_weight', v, pred[k]) _set_weight('out_weight', v, succ[k]) if 'function' in v: v[t] = _parent_blue(v.pop('function'), memo) blue.deferred.append((method, v)) return blue
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'findOutlet'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'shapefile_path'},{'id': '6', 'type': 'block', 'children': ['7', '12', '21', '30', '38', '46', '53', '63', '72', '80', '87', '98', '106', '117', '125', '145', '151', '155', '351', '361', '367']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'check_watershed_boundary_geometry'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'shapefile_path'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'shapefile'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ogr'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Open'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'shapefile_path'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'source_layer'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'shapefile'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'GetLayer'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'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': 'source_lyr_proj'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'source_layer'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'GetSpatialRef'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'osr_geographic_proj'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'osr'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'SpatialReference'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'osr_geographic_proj'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ImportFromEPSG'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'integer', 'children': [], 'value': '4326'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'proj_transform'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'osr'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'CoordinateTransformation'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'source_lyr_proj'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'osr_geographic_proj'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'boundary_feature'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'source_layer'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'GetFeature'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'feat_geom'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'boundary_feature'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'GetGeometryRef'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'feat_geom'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'Transform'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'proj_transform'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'polygon'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'shapely_loads'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'feat_geom'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ExportToWkb'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mask_grid'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'getGrid'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'elevation_grid'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getGrid'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'use_mask'},{'id': '116', 'type': 'False', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'elevation_array'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'elevation_grid'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'np_array'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ma_elevation_array'},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'elevation_array'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '144'], 'value': '=='},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mask_grid'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'np_array'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'min_elevation'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'maxsize'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'outlet_pt'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': 'for_statement', 'children': ['156', '157', '165']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'coord'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'polygon'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'exterior'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'coords'},{'id': '165', 'type': 'block', 'children': ['166', '184', '191', '336']},{'id': '166', 'type': 'try_statement', 'children': ['167', '180']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'pattern_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'mask_grid'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'lonlat2pixel'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'list_splat', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'coord'},{'id': '180', 'type': 'except_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'continue_statement', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'elevation_value'},{'id': '187', 'type': 'subscript', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ma_elevation_array'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '191', 'type': 'if_statement', 'children': ['192', '199']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'elevation_value'},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'masked'},{'id': '199', 'type': 'block', 'children': ['200', '207', '213', '217', '221', '225', '316']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'actual_value'},{'id': '203', 'type': 'subscript', 'children': ['204', '205', '206']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'elevation_array'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'max_diff'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'maxsize'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'nrow'},{'id': '216', 'type': 'None', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ncol'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'nval'},{'id': '224', 'type': 'None', 'children': []},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '246']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'row_ix'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '229', 'type': 'argument_list', 'children': ['230', '237']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '232', 'type': 'argument_list', 'children': ['233', '236']},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '-'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '235', 'type': 'integer', 'children': [], 'value': '5'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '239', 'type': 'argument_list', 'children': ['240', '243']},{'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '+'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '242', 'type': 'integer', 'children': [], 'value': '5'},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'mask_grid'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'y_size'},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'for_statement', 'children': ['248', '249', '268']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'col_ix'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '251', 'type': 'argument_list', 'children': ['252', '259']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '254', 'type': 'argument_list', 'children': ['255', '258']},{'id': '255', 'type': 'binary_operator', 'children': ['256', '257'], 'value': '-'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '257', 'type': 'integer', 'children': [], 'value': '5'},{'id': '258', 'type': 'integer', 'children': [], 'value': '0'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '261', 'type': 'argument_list', 'children': ['262', '265']},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '+'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '264', 'type': 'integer', 'children': [], 'value': '5'},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'mask_grid'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'x_size'},{'id': '268', 'type': 'block', 'children': ['269', '276']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '272', 'type': 'subscript', 'children': ['273', '274', '275']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ma_elevation_array'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'row_ix'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'col_ix'},{'id': '276', 'type': 'if_statement', 'children': ['277', '285']},{'id': '277', 'type': 'not_operator', 'children': ['278']},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': 'is'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '280', 'type': 'attribute', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'masked'},{'id': '285', 'type': 'block', 'children': ['286', '295']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'val_diff'},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'binary_operator', 'children': ['293', '294'], 'value': '-'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'actual_value'},{'id': '295', 'type': 'if_statement', 'children': ['296', '299']},{'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': '<'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'val_diff'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'max_diff'},{'id': '299', 'type': 'block', 'children': ['300', '304', '308', '312']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'max_diff'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'val_diff'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'nval'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'nrow'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'row_ix'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'ncol'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'col_ix'},{'id': '316', 'type': 'if_statement', 'children': ['317', '323']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '319'], 'value': 'not'},{'id': '318', 'type': 'None', 'children': []},{'id': '319', 'type': 'tuple', 'children': ['320', '321', '322']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'nrow'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ncol'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'nval'},{'id': '323', 'type': 'block', 'children': ['324', '328', '332']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'nrow'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'ncol'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'elevation_value'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'nval'},{'id': '336', 'type': 'if_statement', 'children': ['337', '340']},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '339'], 'value': '<'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'elevation_value'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'min_elevation'},{'id': '340', 'type': 'block', 'children': ['341', '345']},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'min_elevation'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'elevation_value'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'outlet_pt'},{'id': '348', 'type': 'tuple', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '351', 'type': 'if_statement', 'children': ['352', '355']},{'id': '352', 'type': 'comparison_operator', 'children': ['353', '354'], 'value': 'is'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'outlet_pt'},{'id': '354', 'type': 'None', 'children': []},{'id': '355', 'type': 'block', 'children': ['356']},{'id': '356', 'type': 'raise_statement', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'string', 'children': [], 'value': "'No valid outlet points found on boundary ...'"},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '366']},{'id': '363', 'type': 'pattern_list', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'outcol'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'outrow'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'outlet_pt'},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'setOutlet'},{'id': '372', 'type': 'argument_list', 'children': ['373', '378']},{'id': '373', 'type': 'keyword_argument', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '+'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'outcol'},{'id': '377', 'type': 'integer', 'children': [], 'value': '1'},{'id': '378', 'type': 'keyword_argument', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '380', 'type': 'binary_operator', 'children': ['381', '382'], 'value': '+'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'outrow'},{'id': '382', 'type': 'integer', 'children': [], 'value': '1'}
def findOutlet(self, shapefile_path): check_watershed_boundary_geometry(shapefile_path) shapefile = ogr.Open(shapefile_path) source_layer = shapefile.GetLayer(0) source_lyr_proj = source_layer.GetSpatialRef() osr_geographic_proj = osr.SpatialReference() osr_geographic_proj.ImportFromEPSG(4326) proj_transform = osr.CoordinateTransformation(source_lyr_proj, osr_geographic_proj) boundary_feature = source_layer.GetFeature(0) feat_geom = boundary_feature.GetGeometryRef() feat_geom.Transform(proj_transform) polygon = shapely_loads(feat_geom.ExportToWkb()) mask_grid = self.getGrid() elevation_grid = self.getGrid(use_mask=False) elevation_array = elevation_grid.np_array() ma_elevation_array = np.ma.array(elevation_array, mask=mask_grid.np_array()==0) min_elevation = sys.maxsize outlet_pt = None for coord in list(polygon.exterior.coords): try: col, row = mask_grid.lonlat2pixel(*coord) except IndexError: continue elevation_value = ma_elevation_array[row, col] if elevation_value is np.ma.masked: actual_value = elevation_array[row, col] max_diff = sys.maxsize nrow = None ncol = None nval = None for row_ix in range(max(row-5, 0), min(row+5, mask_grid.y_size)): for col_ix in range(max(col-5, 0), min(col+5, mask_grid.x_size)): val = ma_elevation_array[row_ix, col_ix] if not val is np.ma.masked: val_diff = abs(val-actual_value) if val_diff < max_diff: max_diff = val_diff nval = val nrow = row_ix ncol = col_ix if None not in (nrow, ncol, nval): row = nrow col = ncol elevation_value = nval if elevation_value < min_elevation: min_elevation = elevation_value outlet_pt = (col, row) if outlet_pt is None: raise IndexError('No valid outlet points found on boundary ...') outcol, outrow = outlet_pt self.setOutlet(col=outcol+1, row=outrow+1)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_write'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '8', 'type': 'block', 'children': ['9', '15']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'precipEvents'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '18', 'type': 'block', 'children': ['19', '37']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': '\'EVENT "%s"\\nNRGAG %s\\nNRPDS %s\\n\''},{'id': '27', 'type': 'tuple', 'children': ['28', '31', '34']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nrGag'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'nrPds'},{'id': '37', 'type': 'if_statement', 'children': ['38', '43']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '>'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'nrGag'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'block', 'children': ['44', '50', '54', '87', '102', '134', '156']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'valList'},{'id': '53', 'type': 'list', 'children': [], 'value': '[]'},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'values'},{'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': 'valList'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'dictionary', 'children': ['65', '70', '75', '82']},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'ValueType'"},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'valueType'},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dateTime'},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'Gage'"},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'gage'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'Value'"},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pivotedValues'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pivot'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pivot'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '99', '101']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'valList'},{'id': '96', 'type': 'tuple', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '98', 'type': 'string', 'children': [], 'value': "'ValueType'"},{'id': '99', 'type': 'tuple', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': "'Gage'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'Value'"},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'gages'},{'id': '105', 'type': 'call', 'children': ['106', '133']},{'id': '106', 'type': 'attribute', 'children': ['107', '131', '132']},{'id': '107', 'type': 'call', 'children': ['108', '127']},{'id': '108', 'type': 'attribute', 'children': ['109', '125', '126']},{'id': '109', 'type': 'call', 'children': ['110', '119']},{'id': '110', 'type': 'attribute', 'children': ['111', '117', '118']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'PrecipGage'},{'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '124'], 'value': '=='},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'PrecipGage'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '125', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'PrecipGage'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '131', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '137']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'gage'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'gages'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '%'},{'id': '145', 'type': 'string', 'children': [], 'value': '\'COORD %s %s "%s"\\n\''},{'id': '146', 'type': 'tuple', 'children': ['147', '150', '153']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'gage'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'gage'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'gage'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'pivotedValues'},{'id': '159', 'type': 'block', 'children': ['160', '164', '183', '206']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '163', 'type': 'string', 'children': [], 'value': "''"},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'list_comprehension', 'children': ['171', '172', '175']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '175', 'type': 'if_clause', 'children': ['176']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '180'], 'value': 'and'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '!='},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '!='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '182', 'type': 'string', 'children': [], 'value': "'ValueType'"},{'id': '183', 'type': 'for_statement', 'children': ['184', '185', '186']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'if_statement', 'children': ['188', '195']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '!='},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '191', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '!='},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '194', 'type': 'string', 'children': [], 'value': "'ValueType'"},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '%'},{'id': '200', 'type': 'string', 'children': [], 'value': "'%s %.3f'"},{'id': '201', 'type': 'tuple', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'},{'id': '213', 'type': 'string', 'children': [], 'value': "'%s %.4d %.2d %.2d %.2d %.2d%s\\n'"},{'id': '214', 'type': 'tuple', 'children': ['215', '218', '223', '228', '233', '238', '243']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '217', 'type': 'string', 'children': [], 'value': "'ValueType'"},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '221', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '226', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '231', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '236', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'hour'},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '241', 'type': 'string', 'children': [], 'value': "'DateTime'"},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'minute'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'valString'}
def _write(self, session, openFile, replaceParamFile): events = self.precipEvents for event in events: openFile.write('EVENT "%s"\nNRGAG %s\nNRPDS %s\n' % (event.description, event.nrGag, event.nrPds)) if event.nrGag > 0: values = event.values valList = [] for value in values: valList.append({'ValueType': value.valueType, 'DateTime': value.dateTime, 'Gage': value.gage.id, 'Value': value.value}) pivotedValues = pivot.pivot(valList, ('DateTime', 'ValueType'), ('Gage',), 'Value') gages = session.query(PrecipGage). \ filter(PrecipGage.event == event). \ order_by(PrecipGage.id). \ all() for gage in gages: openFile.write('COORD %s %s "%s"\n' % (gage.x, gage.y, gage.description)) for row in pivotedValues: valString = '' keys = sorted([key for key in row if key != 'DateTime' and key != 'ValueType']) for key in keys: if key != 'DateTime' and key != 'ValueType': valString = '%s %.3f' % (valString, row[key]) openFile.write('%s %.4d %.2d %.2d %.2d %.2d%s\n' % ( row['ValueType'], row['DateTime'].year, row['DateTime'].month, row['DateTime'].day, row['DateTime'].hour, row['DateTime'].minute, valString))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'valueWritePreprocessor'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'replaceParamsFile'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '26', '30', '90']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': 'is'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '16', 'type': 'block', 'children': ['17', '24']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': '"Only numerical variable types can be handled by the valueReadPreprocessor function."'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'variableString'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'replaceParamsFile'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '39', '44']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'variableString'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'REPLACE_NO_VALUE'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'variableString'},{'id': '43', 'type': 'string', 'children': [], 'value': "'[NO_VARIABLE]'"},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'try_statement', 'children': ['47', '87']},{'id': '47', 'type': 'block', 'children': ['48', '55']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '<'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'block', 'children': ['60', '67']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'parameterID'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '*'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '65', 'type': 'unary_operator', 'children': ['66'], 'value': '-'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '72']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'targetParam'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'replaceParamsFile'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'targetParameters'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'if_statement', 'children': ['74', '79']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '=='},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'targetParam'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'parameterID'},{'id': '79', 'type': 'block', 'children': ['80', '86']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'variableString'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'targetParam'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'targetVariable'},{'id': '86', 'type': 'break_statement', 'children': []},{'id': '87', 'type': 'except_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'pass_statement', 'children': []},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'variableString'}
def valueWritePreprocessor(valueString, replaceParamsFile=None): if type(valueString) is bool: log.warning("Only numerical variable types can be handled by the valueReadPreprocessor function.") return valueString variableString = valueString if replaceParamsFile is not None: if variableString == REPLACE_NO_VALUE: variableString = '[NO_VARIABLE]' else: try: number = int(valueString) if number < 0: parameterID = number * -1 for targetParam in replaceParamsFile.targetParameters: if targetParam.id == parameterID: variableString = targetParam.targetVariable break except: pass return variableString
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_createGsshaPyObjects'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mapTables'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'indexMaps'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'spatial'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'spatialReferenceID'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mapTables'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'try_statement', 'children': ['18', '295']},{'id': '18', 'type': 'block', 'children': ['19', '32', '87', '93', '108']},{'id': '19', 'type': 'if_statement', 'children': ['20', '25']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': 'is'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '23', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'indexMaps'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '31', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'MapTable'},{'id': '37', 'type': 'argument_list', 'children': ['38', '43', '50', '57', '67', '77']},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '42', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'numIDs'},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '48', 'type': 'string', 'children': [], 'value': "'numVars'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'NUM_IDS'"},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'maxNumCells'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '55', 'type': 'string', 'children': [], 'value': "'numVars'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'MAX_NUMBER_CELLS'"},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'numSed'},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '63', 'type': 'string', 'children': [], 'value': "'numVars'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': "'NUM_SED'"},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'numContam'},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '73', 'type': 'string', 'children': [], 'value': "'numVars'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'NUM_CONTAM'"},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'maxSoilID'},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '83', 'type': 'string', 'children': [], 'value': "'numVars'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "'MAX_SOIL_ID'"},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'mapTableFile'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '96', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'indexMaps'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '107', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '108', 'type': 'if_statement', 'children': ['109', '114', '216', '269']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '112', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'CONTAMINANT_TRANSPORT'"},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '120']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '119', 'type': 'string', 'children': [], 'value': "'contaminants'"},{'id': '120', 'type': 'block', 'children': ['121', '132', '175', '183', '189', '205']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'outputBaseFilename'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_preprocessContaminantOutFilePath'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '131', 'type': 'string', 'children': [], 'value': "'outPath'"},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'MTContaminant'},{'id': '137', 'type': 'argument_list', 'children': ['138', '143', '146', '157', '168']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '142', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'outputFilename'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'outputBaseFilename'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'precipConc'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'vrp'},{'id': '150', 'type': 'argument_list', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '154', 'type': 'string', 'children': [], 'value': "'contamVars'"},{'id': '155', 'type': 'string', 'children': [], 'value': "'PRECIP_CONC'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'vrp'},{'id': '161', 'type': 'argument_list', 'children': ['162', '167']},{'id': '162', 'type': 'subscript', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '165', 'type': 'string', 'children': [], 'value': "'contamVars'"},{'id': '166', 'type': 'string', 'children': [], 'value': "'PARTITION'"},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'numIDs'},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '173', 'type': 'string', 'children': [], 'value': "'contamVars'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'NUM_IDS'"},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'indexMaps'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '182', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_createValueObjects'},{'id': '194', 'type': 'argument_list', 'children': ['195', '198', '201', '202', '203', '204']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '197', 'type': 'string', 'children': [], 'value': "'valueList'"},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'contam'},{'id': '200', 'type': 'string', 'children': [], 'value': "'varList'"},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_readContaminantOutputFiles'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212', '213', '214', '215']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'outputBaseFilename'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'spatial'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'spatialReferenceID'},{'id': '216', 'type': 'elif_clause', 'children': ['217', '222']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': '=='},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '220', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '221', 'type': 'string', 'children': [], 'value': "'SEDIMENTS'"},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'for_statement', 'children': ['224', '225', '228']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '227', 'type': 'string', 'children': [], 'value': "'valueList'"},{'id': '228', 'type': 'block', 'children': ['229', '263']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sediment'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'MTSediment'},{'id': '234', 'type': 'argument_list', 'children': ['235', '240', '249', '258']},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'specificGravity'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'vrp'},{'id': '244', 'type': 'argument_list', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'particleDiameter'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'vrp'},{'id': '253', 'type': 'argument_list', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '256', 'type': 'integer', 'children': [], 'value': '2'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'outputFilename'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '262', 'type': 'integer', 'children': [], 'value': '3'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sediment'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '269', 'type': 'else_clause', 'children': ['270']},{'id': '270', 'type': 'block', 'children': ['271', '279']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'indexMaps'},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '278', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_createValueObjects'},{'id': '284', 'type': 'argument_list', 'children': ['285', '288', '291', '292', '293', '294']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '287', 'type': 'string', 'children': [], 'value': "'valueList'"},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '290', 'type': 'string', 'children': [], 'value': "'varList'"},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '293', 'type': 'None', 'children': []},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'replaceParamFile'},{'id': '295', 'type': 'except_clause', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'binary_operator', 'children': ['305', '309'], 'value': '%'},{'id': '305', 'type': '()', 'children': ['306']},{'id': '306', 'type': 'concatenated_string', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': '\'Index Map "%s" for Mapping Table "%s" not found in list of index maps in the mapping \''},{'id': '308', 'type': 'string', 'children': [], 'value': "'table file. The Mapping Table was not read into the database.'"},{'id': '309', 'type': 'tuple', 'children': ['310', '313']},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '312', 'type': 'string', 'children': [], 'value': "'indexMapName'"},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'mt'},{'id': '315', 'type': 'string', 'children': [], 'value': "'name'"}
def _createGsshaPyObjects(self, mapTables, indexMaps, replaceParamFile, directory, session, spatial, spatialReferenceID): for mt in mapTables: try: if mt['indexMapName'] is not None: indexMaps[mt['indexMapName']] mapTable = MapTable(name=mt['name'], numIDs=mt['numVars']['NUM_IDS'], maxNumCells=mt['numVars']['MAX_NUMBER_CELLS'], numSed=mt['numVars'].get('NUM_SED'), numContam=mt['numVars'].get('NUM_CONTAM'), maxSoilID=mt['numVars'].get('MAX_SOIL_ID')) mapTable.mapTableFile = self if mt['indexMapName']: mapTable.indexMap = indexMaps[mt['indexMapName']] if mt['name'] == 'CONTAMINANT_TRANSPORT': for contam in mt['contaminants']: outputBaseFilename = self._preprocessContaminantOutFilePath(contam['outPath']) contaminant = MTContaminant(name=contam['name'], outputFilename=outputBaseFilename, precipConc=vrp(contam['contamVars']['PRECIP_CONC'], replaceParamFile), partition=vrp(contam['contamVars']['PARTITION'], replaceParamFile), numIDs=contam['contamVars']['NUM_IDS']) indexMap = indexMaps[contam['indexMapName']] contaminant.indexMap = indexMap self._createValueObjects(contam['valueList'], contam['varList'], mapTable, indexMap, contaminant, replaceParamFile) self._readContaminantOutputFiles(directory, outputBaseFilename, session, spatial, spatialReferenceID) elif mt['name'] == 'SEDIMENTS': for line in mt['valueList']: sediment = MTSediment(description=line[0], specificGravity=vrp(line[1], replaceParamFile), particleDiameter=vrp(line[2], replaceParamFile), outputFilename=line[3]) sediment.mapTable = mapTable else: indexMap = indexMaps[mt['indexMapName']] self._createValueObjects(mt['valueList'], mt['varList'], mapTable, indexMap, None, replaceParamFile) except KeyError: log.info(('Index Map "%s" for Mapping Table "%s" not found in list of index maps in the mapping ' 'table file. The Mapping Table was not read into the database.') % ( mt['indexMapName'], mt['name']))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_valuePivot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'replaceParaFile'},{'id': '9', 'type': 'block', 'children': ['10', '60', '65', '81', '85', '89', '345', '349', '404', '420', '428']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '13', 'type': 'call', 'children': ['14', '59']},{'id': '14', 'type': 'attribute', 'children': ['15', '57', '58']},{'id': '15', 'type': 'call', 'children': ['16', '53']},{'id': '16', 'type': 'attribute', 'children': ['17', '51', '52']},{'id': '17', 'type': 'call', 'children': ['18', '45']},{'id': '18', 'type': 'attribute', 'children': ['19', '43', '44']},{'id': '19', 'type': 'call', 'children': ['20', '37']},{'id': '20', 'type': 'attribute', 'children': ['21', '35', '36']},{'id': '21', 'type': 'call', 'children': ['22', '31']},{'id': '22', 'type': 'attribute', 'children': ['23', '29', '30']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'MTIndex'},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '35', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '=='},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '43', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '=='},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '51', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'MTIndex'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '57', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'layer_indices'},{'id': '63', 'type': 'list', 'children': ['64'], 'value': '[0]'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'if_statement', 'children': ['66', '73']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': 'in'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'MULTI_LAYER_SOIL'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'RICHARDS_EQN_INFILTRATION_BROOKS'"},{'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': 'layer_indices'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'integer', 'children': [], 'value': '3'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '84', 'type': 'list', 'children': [], 'value': '[]'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '88', 'type': 'dictionary', 'children': []},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'layer_index'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'layer_indices'},{'id': '96', 'type': 'block', 'children': ['97', '159', '163', '213', '231', '246', '261', '338']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '100', 'type': 'call', 'children': ['101', '158']},{'id': '101', 'type': 'attribute', 'children': ['102', '156', '157']},{'id': '102', 'type': 'call', 'children': ['103', '152']},{'id': '103', 'type': 'attribute', 'children': ['104', '150', '151']},{'id': '104', 'type': 'call', 'children': ['105', '144']},{'id': '105', 'type': 'attribute', 'children': ['106', '142', '143']},{'id': '106', 'type': 'call', 'children': ['107', '136']},{'id': '107', 'type': 'attribute', 'children': ['108', '134', '135']},{'id': '108', 'type': 'call', 'children': ['109', '128']},{'id': '109', 'type': 'attribute', 'children': ['110', '126', '127']},{'id': '110', 'type': 'call', 'children': ['111', '120']},{'id': '111', 'type': 'attribute', 'children': ['112', '118', '119']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '118', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '126', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'contaminant'},{'id': '134', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '141'], 'value': '=='},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '142', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '=='},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'layer_id'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'layer_index'},{'id': '150', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '156', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '162', 'type': 'string', 'children': [], 'value': "''"},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '166', 'type': 'block', 'children': ['167', '176', '186', '202']},{'id': '167', 'type': 'if_statement', 'children': ['168', '174']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': '<='},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '-'},{'id': '173', 'type': 'integer', 'children': [], 'value': '9999'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'continue_statement', 'children': []},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'processedValue'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'vwp'},{'id': '181', 'type': 'argument_list', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'replaceParaFile'},{'id': '186', 'type': 'try_statement', 'children': ['187', '194']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'numString'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '%'},{'id': '192', 'type': 'string', 'children': [], 'value': "'%.6f'"},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'processedValue'},{'id': '194', 'type': 'except_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'numString'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '%'},{'id': '200', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'processedValue'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '%'},{'id': '206', 'type': 'string', 'children': [], 'value': "'%s%s%s'"},{'id': '207', 'type': 'tuple', 'children': ['208', '209', '210']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'numString'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '*'},{'id': '211', 'type': 'string', 'children': [], 'value': "' '"},{'id': '212', 'type': 'integer', 'children': [], 'value': '3'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'spacing1'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '-'},{'id': '221', 'type': 'integer', 'children': [], 'value': '6'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'spacing2'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238']},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '-'},{'id': '239', 'type': 'integer', 'children': [], 'value': '40'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'description1'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'spacing3'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253']},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '-'},{'id': '254', 'type': 'integer', 'children': [], 'value': '40'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'description2'},{'id': '261', 'type': 'if_statement', 'children': ['262', '265', '291']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '=='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'layer_index'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '%'},{'id': '270', 'type': 'string', 'children': [], 'value': "'%s%s%s%s%s%s%s\\n'"},{'id': '271', 'type': 'tuple', 'children': ['272', '275', '278', '281', '284', '287', '290']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '*'},{'id': '276', 'type': 'string', 'children': [], 'value': "' '"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'spacing1'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'description1'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '*'},{'id': '282', 'type': 'string', 'children': [], 'value': "' '"},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'spacing2'},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'description2'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '*'},{'id': '288', 'type': 'string', 'children': [], 'value': "' '"},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'spacing3'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '291', 'type': 'else_clause', 'children': ['292']},{'id': '292', 'type': 'block', 'children': ['293', '326']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'num_prepend_spaces'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '325'], 'value': '+'},{'id': '297', 'type': 'binary_operator', 'children': ['298', '319'], 'value': '+'},{'id': '298', 'type': 'binary_operator', 'children': ['299', '317', '318'], 'value': '+'},{'id': '299', 'type': 'binary_operator', 'children': ['300', '311'], 'value': '+'},{'id': '300', 'type': 'binary_operator', 'children': ['301', '310'], 'value': '+'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'spacing1'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'description1'},{'id': '317', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'spacing2'},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'description2'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'spacing3'},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'string', 'children': [], 'value': "'{0}{1}\\n'"},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '333', 'type': 'argument_list', 'children': ['334', '337']},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '*'},{'id': '335', 'type': 'string', 'children': [], 'value': "' '"},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'num_prepend_spaces'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '348', 'type': 'string', 'children': [], 'value': "''"},{'id': '349', 'type': 'for_statement', 'children': ['350', '353', '357']},{'id': '350', 'type': 'pattern_list', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'if_statement', 'children': ['359', '364', '389']},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '363'], 'value': '=='},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '363', 'type': 'string', 'children': [], 'value': "'XSEDIMENT'"},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'if_statement', 'children': ['366', '374']},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '>='},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '368', 'type': 'binary_operator', 'children': ['369', '373'], 'value': '-'},{'id': '369', 'type': 'call', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '373', 'type': 'integer', 'children': [], 'value': '1'},{'id': '374', 'type': 'block', 'children': ['375']},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'assignment', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '378', 'type': 'binary_operator', 'children': ['379', '380'], 'value': '%'},{'id': '379', 'type': 'string', 'children': [], 'value': "'%s%s%s%s'"},{'id': '380', 'type': 'tuple', 'children': ['381', '382', '385', '386']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'numSed'},{'id': '385', 'type': 'string', 'children': [], 'value': "' SEDIMENTS....'"},{'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '*'},{'id': '387', 'type': 'string', 'children': [], 'value': "' '"},{'id': '388', 'type': 'integer', 'children': [], 'value': '2'},{'id': '389', 'type': 'else_clause', 'children': ['390']},{'id': '390', 'type': 'block', 'children': ['391']},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'assignment', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '394', 'type': 'binary_operator', 'children': ['395', '396'], 'value': '%'},{'id': '395', 'type': 'string', 'children': [], 'value': "'%s%s%s'"},{'id': '396', 'type': 'tuple', 'children': ['397', '398', '401']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '401', 'type': 'binary_operator', 'children': ['402', '403'], 'value': '*'},{'id': '402', 'type': 'string', 'children': [], 'value': "' '"},{'id': '403', 'type': 'integer', 'children': [], 'value': '2'},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'assignment', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '407', 'type': 'binary_operator', 'children': ['408', '409'], 'value': '%'},{'id': '408', 'type': 'string', 'children': [], 'value': "'ID%sDESCRIPTION1%sDESCRIPTION2%s%s\\n'"},{'id': '409', 'type': 'tuple', 'children': ['410', '413', '416', '419']},{'id': '410', 'type': 'binary_operator', 'children': ['411', '412'], 'value': '*'},{'id': '411', 'type': 'string', 'children': [], 'value': "' '"},{'id': '412', 'type': 'integer', 'children': [], 'value': '4'},{'id': '413', 'type': 'binary_operator', 'children': ['414', '415'], 'value': '*'},{'id': '414', 'type': 'string', 'children': [], 'value': "' '"},{'id': '415', 'type': 'integer', 'children': [], 'value': '28'},{'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '*'},{'id': '417', 'type': 'string', 'children': [], 'value': "' '"},{'id': '418', 'type': 'integer', 'children': [], 'value': '28'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'varString'},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'call', 'children': ['422', '425']},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '425', 'type': 'argument_list', 'children': ['426', '427']},{'id': '426', 'type': 'integer', 'children': [], 'value': '0'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '428', 'type': 'return_statement', 'children': ['429']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'lines'}
def _valuePivot(self, session, mapTable, contaminant, replaceParaFile): indexes = session.query(MTIndex). \ join(MTValue.index). \ filter(MTValue.mapTable == mapTable). \ filter(MTValue.contaminant == contaminant). \ order_by(MTIndex.index). \ all() layer_indices = [0] if mapTable.name in ('MULTI_LAYER_SOIL', 'RICHARDS_EQN_INFILTRATION_BROOKS'): layer_indices = range(3) lines = [] values = {} for idx in indexes: for layer_index in layer_indices: values = session.query(MTValue). \ filter(MTValue.mapTable == mapTable). \ filter(MTValue.contaminant == contaminant). \ filter(MTValue.index == idx). \ filter(MTValue.layer_id == layer_index). \ order_by(MTValue.id). \ all() valString = '' for val in values: if val.value <= -9999: continue processedValue = vwp(val.value, replaceParaFile) try: numString = '%.6f' % processedValue except: numString = '%s' % processedValue valString = '%s%s%s' % (valString, numString, ' ' * 3) spacing1 = max(1, 6 - len(str(idx.index))) spacing2 = max(1, 40 - len(idx.description1)) spacing3 = max(1, 40 - len(idx.description2)) if layer_index == 0: line = '%s%s%s%s%s%s%s\n' % ( idx.index, ' ' * spacing1, idx.description1, ' ' * spacing2, idx.description2, ' ' * spacing3, valString) else: num_prepend_spaces = len(str(idx.index)) + spacing1 + len(idx.description1) \ + spacing2 + len(idx.description2) + spacing3 line = '{0}{1}\n'.format(' ' * num_prepend_spaces, valString) lines.append(line) varString = '' for idx, val in enumerate(values): if val.variable == 'XSEDIMENT': if idx >= len(values) - 1: varString = '%s%s%s%s' % (varString, mapTable.numSed, ' SEDIMENTS....', ' ' * 2) else: varString = '%s%s%s' % (varString, val.variable, ' ' * 2) header = 'ID%sDESCRIPTION1%sDESCRIPTION2%s%s\n' % (' ' * 4, ' ' * 28, ' ' * 28, varString) lines.insert(0, header) return lines
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'addRoughnessMapFromLandUse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'land_use_grid'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'land_use_grid_id'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '28', '136', '147', '169', '182', '195', '218', '226', '252', '261', '267', '273', '279', '331', '342', '358', '371', '397']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'LAND_USE_GRID_TABLES'},{'id': '18', 'type': 'dictionary', 'children': ['19', '22', '25']},{'id': '19', 'type': 'pair', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'nga'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'land_cover_nga.txt'"},{'id': '22', 'type': 'pair', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "'glcf'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'land_cover_glcf_modis.txt'"},{'id': '25', 'type': 'pair', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'nlcd'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'land_cover_nlcd.txt'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '36', '41']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43', '89', '100']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48', '58']},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'land_use_grid_id'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'raise_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"Must have land_use_to_roughness_table or land_use_grid_id set ..."'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '67', 'type': 'argument_list', 'children': ['68', '83', '84', '85', '86']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': '__file__'},{'id': '83', 'type': 'string', 'children': [], 'value': "'..'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'grid'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'land_cover'"},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'LAND_USE_GRID_TABLES'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'land_use_grid_id'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'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': 'abspath'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'read_table'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '112', '115', '118', '124']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'land_use_to_roughness_table'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'delim_whitespace'},{'id': '111', 'type': 'True', 'children': []},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'skiprows'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '120', 'type': 'tuple', 'children': ['121', '122', '123']},{'id': '121', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '122', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'roughness'"},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '126', 'type': 'dictionary', 'children': ['127', '130', '133']},{'id': '127', 'type': 'pair', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '129', 'type': 'string', 'children': [], 'value': "'int'"},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '132', 'type': 'string', 'children': [], 'value': "'str'"},{'id': '133', 'type': 'pair', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'roughness'"},{'id': '135', 'type': 'string', 'children': [], 'value': "'float'"},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'land_use_grid'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'land_use_grid'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'land_use_resampled'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'resample_grid'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154', '161', '166']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'land_use_grid'},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'getGrid'},{'id': '160', 'type': 'argument_list', 'children': []},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'resample_method'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'gdalconst'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'GRA_NearestNeighbour'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'as_gdal_grid'},{'id': '168', 'type': 'True', 'children': []},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'unique_land_use_ids'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'land_use_resampled'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'np_array'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '187', 'type': 'call', 'children': ['188', '193']},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'unique_land_use_ids'},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'land_use_id'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'unique_land_use_ids'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'if_statement', 'children': ['200', '207']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'not'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'land_use_id'},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'raise_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': '"Land use ID {0} not found in table."'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'land_use_id'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'deleteMapTable'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225']},{'id': '224', 'type': 'string', 'children': [], 'value': '"ROUGHNESS"'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'MapTable'},{'id': '231', 'type': 'argument_list', 'children': ['232', '235', '243', '246', '249']},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '234', 'type': 'string', 'children': [], 'value': '"ROUGHNESS"'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'numIDs'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'maxNumCells'},{'id': '245', 'type': 'integer', 'children': [], 'value': '0'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'numSed'},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'numContam'},{'id': '251', 'type': 'integer', 'children': [], 'value': '0'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'IndexMap'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'mapTableFile'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'mapTableFile'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'for_statement', 'children': ['280', '281', '286']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'itertuples'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'block', 'children': ['287', '303', '309', '319', '325']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'MTIndex'},{'id': '292', 'type': 'argument_list', 'children': ['293', '299', '302']},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '302', 'type': 'string', 'children': [], 'value': "''"},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'MTValue'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'string', 'children': [], 'value': "'ROUGH'"},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'roughness'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'manningn_card'},{'id': '334', 'type': 'call', 'children': ['335', '340']},{'id': '335', 'type': 'attribute', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'getCard'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'string', 'children': [], 'value': "'MANNING_N'"},{'id': '342', 'type': 'if_statement', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'manningn_card'},{'id': '344', 'type': 'block', 'children': ['345', '352']},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'manningn_card'},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '357', 'type': 'argument_list', 'children': []},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '365']},{'id': '360', 'type': 'attribute', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'string', 'children': [], 'value': "'{0}.idx'"},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '371', 'type': 'with_statement', 'children': ['372', '382']},{'id': '372', 'type': 'with_clause', 'children': ['373']},{'id': '373', 'type': 'with_item', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'tmp_chdir'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'attribute', 'children': ['378', '381']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'project_directory'},{'id': '382', 'type': 'block', 'children': ['383']},{'id': '383', 'type': 'expression_statement', 'children': ['384']},{'id': '384', 'type': 'call', 'children': ['385', '388']},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'land_use_resampled'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'to_grass_ascii'},{'id': '388', 'type': 'argument_list', 'children': ['389', '394']},{'id': '389', 'type': 'attribute', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'mapTable'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'indexMap'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '394', 'type': 'keyword_argument', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'print_nodata'},{'id': '396', 'type': 'False', 'children': []},{'id': '397', 'type': 'if_statement', 'children': ['398', '407']},{'id': '398', 'type': 'not_operator', 'children': ['399']},{'id': '399', 'type': 'call', 'children': ['400', '405']},{'id': '400', 'type': 'attribute', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'getCard'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'string', 'children': [], 'value': "'MAPPING_TABLE'"},{'id': '407', 'type': 'block', 'children': ['408']},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '415']},{'id': '410', 'type': 'attribute', 'children': ['411', '414']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'setCard'},{'id': '415', 'type': 'argument_list', 'children': ['416', '417', '427']},{'id': '416', 'type': 'string', 'children': [], 'value': "'MAPPING_TABLE'"},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'string', 'children': [], 'value': "'{0}.cmt'"},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'attribute', 'children': ['423', '426']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'projectFile'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '427', 'type': 'keyword_argument', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'add_quotes'},{'id': '429', 'type': 'True', 'children': []}
def addRoughnessMapFromLandUse(self, name, session, land_use_grid, land_use_to_roughness_table=None, land_use_grid_id=None, ): LAND_USE_GRID_TABLES = { 'nga' : 'land_cover_nga.txt', 'glcf' : 'land_cover_glcf_modis.txt', 'nlcd' : 'land_cover_nlcd.txt', } if isinstance(land_use_to_roughness_table, pd.DataFrame): df = land_use_to_roughness_table else: if land_use_to_roughness_table is None: if land_use_grid_id is None: raise ValueError("Must have land_use_to_roughness_table or land_use_grid_id set ...") land_use_to_roughness_table = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'grid', 'land_cover', LAND_USE_GRID_TABLES[land_use_grid_id]) land_use_to_roughness_table = os.path.abspath(land_use_to_roughness_table) df = pd.read_table(land_use_to_roughness_table, delim_whitespace=True, header=None, skiprows=1, names=('id', 'description', 'roughness'), dtype={'id':'int', 'description':'str', 'roughness':'float'}, ) land_use_grid = os.path.abspath(land_use_grid) land_use_resampled = resample_grid(land_use_grid, self.projectFile.getGrid(), resample_method=gdalconst.GRA_NearestNeighbour, as_gdal_grid=True) unique_land_use_ids = np.unique(land_use_resampled.np_array()) df = df[df.id.isin(unique_land_use_ids)] for land_use_id in unique_land_use_ids: if land_use_id not in df.id.values: raise IndexError("Land use ID {0} not found in table.".format(land_use_id)) self.deleteMapTable("ROUGHNESS", session) mapTable = MapTable(name="ROUGHNESS", numIDs=len(df.index), maxNumCells=0, numSed=0, numContam=0) indexMap = IndexMap(name=name) indexMap.mapTableFile = self mapTable.indexMap = indexMap mapTable.mapTableFile = self for row in df.itertuples(): idx = MTIndex(str(row.id), row.description, '') idx.indexMap = indexMap val = MTValue('ROUGH', row.roughness) val.index = idx val.mapTable = mapTable manningn_card = self.projectFile.getCard('MANNING_N') if manningn_card: session.delete(manningn_card) session.commit() mapTable.indexMap.filename = '{0}.idx'.format(name) with tmp_chdir(self.projectFile.project_directory): land_use_resampled.to_grass_ascii(mapTable.indexMap.filename, print_nodata=False) if not self.projectFile.getCard('MAPPING_TABLE'): self.projectFile.setCard('MAPPING_TABLE', '{0}.cmt'.format(self.projectFile.name), add_quotes=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'result'},{'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': 'timeout'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '29', '102', '184', '196', '262', '272']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '15']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'future_lists'},{'id': '15', 'type': 'expression_list', 'children': ['16', '17', '18']},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'import_from_statement', 'children': ['20', '23', '25']},{'id': '20', 'type': 'dotted_name', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'concurrent'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '23', 'type': 'dotted_name', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '25', 'type': 'aliased_import', 'children': ['26', '28']},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'wait_fut'},{'id': '29', 'type': 'function_definition', 'children': ['30', '31', '35']},{'id': '30', 'type': 'function_name', 'children': [], 'value': 'update'},{'id': '31', 'type': 'parameters', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '42', '53']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'tuple', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'elif_clause', 'children': ['54', '63']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '60'], 'value': 'and'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'AsyncList'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'not'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'future_lists'},{'id': '63', 'type': 'block', 'children': ['64', '71']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'future_lists'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '97']},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '83', '91']},{'id': '79', 'type': 'tuple', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '83', 'type': 'for_in_clause', 'children': ['84', '87']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'fut'},{'id': '91', 'type': 'if_clause', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '97', 'type': 'slice', 'children': ['98', '99', '100']},{'id': '98', 'type': 'colon', 'children': []},{'id': '99', 'type': 'colon', 'children': []},{'id': '100', 'type': 'unary_operator', 'children': ['101'], 'value': '-'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'for_statement', 'children': ['103', '104', '111']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '104', 'type': 'call', 'children': ['105', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sub_sol'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'block', 'children': ['112', '132', '158']},{'id': '112', 'type': 'for_statement', 'children': ['113', '116', '124']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '143']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '134', 'type': 'call', 'children': ['135', '142']},{'id': '135', 'type': 'attribute', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'},{'id': '146', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '152', 'type': 'argument_list', 'children': ['153', '156', '157']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '155', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '157', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '169']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '160', 'type': 'call', 'children': ['161', '168']},{'id': '161', 'type': 'attribute', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'if_statement', 'children': ['171', '174']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'in'},{'id': '172', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '178', 'type': 'argument_list', 'children': ['179', '182', '183']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '181', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '183', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'wait_fut'},{'id': '187', 'type': 'argument_list', 'children': ['188', '195']},{'id': '188', 'type': 'set_comprehension', 'children': ['189', '192']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '191', 'type': 'integer', 'children': [], 'value': '0'},{'id': '192', 'type': 'for_in_clause', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '196', 'type': 'for_statement', 'children': ['197', '201', '202']},{'id': '197', 'type': 'pattern_list', 'children': ['198', '199', '200']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'try_statement', 'children': ['204', '215', '238']},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'await_result'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'except_clause', 'children': ['216', '220']},{'id': '216', 'type': 'as_pattern', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'SkipNode'},{'id': '218', 'type': 'as_pattern_target', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '220', 'type': 'block', 'children': ['221', '234']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'tuple', 'children': ['228', '229', '230', '231']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '234', 'type': 'delete_statement', 'children': ['235']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '238', 'type': 'except_clause', 'children': ['239', '246']},{'id': '239', 'type': 'as_pattern', 'children': ['240', '244']},{'id': '240', 'type': 'tuple', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ExecutorShutdown'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'DispatcherAbort'},{'id': '244', 'type': 'as_pattern_target', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '246', 'type': 'block', 'children': ['247', '258']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'tuple', 'children': ['254', '255', '256', '257']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '258', 'type': 'delete_statement', 'children': ['259']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '262', 'type': 'if_statement', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'raise_statement', 'children': ['266']},{'id': '266', 'type': 'subscript', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'unary_operator', 'children': ['271'], 'value': '-'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'}
def result(self, timeout=None): it, exceptions, future_lists = [], [], [] from concurrent.futures import Future, wait as wait_fut def update(fut, data, key): if isinstance(fut, Future): it.append((fut, data, key)) elif isinstance(fut, AsyncList) and fut not in future_lists: future_lists.append(fut) it.extend([(j, fut, i) for i, j in enumerate(fut) if isinstance(j, Future)][::-1]) for s in self.sub_sol.values(): for k, v in list(s.items()): update(v, s, k) for d in s.workflow.nodes.values(): if 'results' in d: update(d['results'], d, 'results') for d in s.workflow.edges.values(): if 'value' in d: update(d['value'], d, 'value') wait_fut({v[0] for v in it}, timeout) for f, d, k in it: try: d[k] = await_result(f, 0) except SkipNode as e: exceptions.append((f, d, k, e.ex)) del d[k] except (Exception, ExecutorShutdown, DispatcherAbort) as ex: exceptions.append((f, d, k, ex)) del d[k] if exceptions: raise exceptions[0][-1] return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_data_node_output'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'next_nds'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '13', 'type': 'block', 'children': ['14', '26', '154', '289']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '19']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'est'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_get_node_estimations'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '26', 'type': 'if_statement', 'children': ['27', '29', '142']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '29', 'type': 'block', 'children': ['30', '55', '78', '104', '124', '135']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'PLOT'},{'id': '34', 'type': 'block', 'children': ['35', '43']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'est'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'est'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'est'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'PLOT'},{'id': '48', 'type': 'dictionary', 'children': ['49']},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '51', 'type': 'dictionary', 'children': ['52']},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'obj'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'sf'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '60', 'type': 'expression_list', 'children': ['61', '62']},{'id': '61', 'type': 'False', 'children': []},{'id': '62', 'type': 'tuple', 'children': ['63']},{'id': '63', 'type': 'dictionary_comprehension', 'children': ['64', '69']},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '69', 'type': 'for_in_clause', 'children': ['70', '73']},{'id': '70', 'type': 'pattern_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'est'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '86']},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': '()', 'children': ['81']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '83'], 'value': 'or'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'},{'id': '84', 'type': 'string', 'children': [], 'value': "'function'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '92']},{'id': '89', 'type': 'pattern_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '92', 'type': 'expression_list', 'children': ['93', '94']},{'id': '93', 'type': 'True', 'children': []},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'try_statement', 'children': ['105', '119']},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'async_thread'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114', '115', '116', '117']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '117', 'type': 'dictionary_splat', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '119', 'type': 'except_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'SkipNode'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'False', 'children': []},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'dictionary', 'children': ['139']},{'id': '139', 'type': 'pair', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144', '150']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '153', 'type': 'dictionary', 'children': []},{'id': '154', 'type': 'if_statement', 'children': ['155', '156', '175']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'next_nds'},{'id': '156', 'type': 'block', 'children': ['157', '163']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_wf_add_edge'},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'next_nds'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '173', 'type': 'dictionary_splat', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '175', 'type': 'else_clause', 'children': ['176']},{'id': '176', 'type': 'block', 'children': ['177', '195', '243', '260']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '183']},{'id': '179', 'type': 'pattern_list', 'children': ['180', '181', '182']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'has'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sub_sol'},{'id': '183', 'type': 'expression_list', 'children': ['184', '187', '192']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'has_edge'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'sub_sol'},{'id': '195', 'type': 'function_definition', 'children': ['196', '197', '199']},{'id': '196', 'type': 'function_name', 'children': [], 'value': 'no_visited_in_sub_dsp'},{'id': '197', 'type': 'parameters', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'block', 'children': ['200', '206', '241']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'if_statement', 'children': ['207', '218']},{'id': '207', 'type': 'boolean_operator', 'children': ['208', '213'], 'value': 'and'},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': '=='},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '211', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '212', 'type': 'string', 'children': [], 'value': "'dispatcher'"},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'has'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '218', 'type': 'block', 'children': ['219', '233']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '222', 'type': 'attribute', 'children': ['223', '232']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'sub_sol'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '229'], 'value': '+'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '231', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': '_visited'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '240'], 'value': 'not'},{'id': '235', 'type': 'subscript', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '238', 'type': 'string', 'children': [], 'value': "'inputs'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'True', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'succ_fun'},{'id': '246', 'type': 'list_comprehension', 'children': ['247', '248', '255']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '248', 'type': 'for_in_clause', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_succ'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '255', 'type': 'if_clause', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'no_visited_in_sub_dsp'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '260', 'type': 'if_statement', 'children': ['261', '270']},{'id': '261', 'type': 'boolean_operator', 'children': ['262', '263'], 'value': 'and'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'succ_fun'},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '267'], 'value': 'not'},{'id': '264', 'type': 'subscript', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'succ_fun'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_visited'},{'id': '270', 'type': 'block', 'children': ['271', '277']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': '_wf_add_edge'},{'id': '277', 'type': 'for_statement', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'succ_fun'},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '284', 'type': 'argument_list', 'children': ['285', '286', '287']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '287', 'type': 'dictionary_splat', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '289', 'type': 'return_statement', 'children': ['290']},{'id': '290', 'type': 'True', 'children': []}
def _set_data_node_output(self, node_id, node_attr, no_call, next_nds=None, **kw): est, wait_in = self._get_node_estimations(node_attr, node_id) if not no_call: if node_id is PLOT: est = est.copy() est[PLOT] = {'value': {'obj': self}} sf, args = False, ({k: v['value'] for k, v in est.items()},) if not (wait_in or 'function' in node_attr): sf, args = True, tuple(args[0].values()) try: value = async_thread(self, args, node_attr, node_id, sf, **kw) except SkipNode: return False if value is not NONE: self[node_id] = value value = {'value': value} else: self[node_id] = NONE value = {} if next_nds: wf_add_edge = self._wf_add_edge for u in next_nds: wf_add_edge(node_id, u, **value) else: n, has, sub_sol = self.nodes, self.workflow.has_edge, self.sub_sol def no_visited_in_sub_dsp(i): node = n[i] if node['type'] == 'dispatcher' and has(i, node_id): visited = sub_sol[self.index + node['index']]._visited return node['inputs'][node_id] not in visited return True succ_fun = [u for u in self._succ[node_id] if no_visited_in_sub_dsp(u)] if succ_fun and succ_fun[0] not in self._visited: wf_add_edge = self._wf_add_edge for u in succ_fun: wf_add_edge(node_id, u, **value) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_function_node_output'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'next_nds'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '13', 'type': 'block', 'children': ['14', '26', '44', '59', '65', '80', '88', '102', '142', '179']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '19']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'o_nds'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '19', 'type': 'expression_list', 'children': ['20', '23']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '22', 'type': 'string', 'children': [], 'value': "'outputs'"},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'output_nodes'},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '31'], 'value': 'or'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'next_nds'},{'id': '31', 'type': 'call', 'children': ['32', '42']},{'id': '32', 'type': 'attribute', 'children': ['33', '41']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_succ'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '44', 'type': 'if_statement', 'children': ['45', '47']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'output_nodes'},{'id': '47', 'type': 'block', 'children': ['48', '57']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'remove_node'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'False', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_wf_add_edge'},{'id': '65', 'type': 'if_statement', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '67', 'type': 'block', 'children': ['68', '78']},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'output_nodes'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'True', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': '_wf_pred'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '96', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '101', 'type': 'string', 'children': [], 'value': "'inputs'"},{'id': '102', 'type': 'try_statement', 'children': ['103', '137']},{'id': '103', 'type': 'block', 'children': ['104', '113', '125']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_check_function_domain'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'async_thread'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121', '122', '123']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'node_attr'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '123', 'type': 'dictionary_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '136']},{'id': '127', 'type': 'subscript', 'children': ['128', '135']},{'id': '128', 'type': 'subscript', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '135', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '137', 'type': 'except_clause', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'SkipNode'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'False', 'children': []},{'id': '142', 'type': 'for_statement', 'children': ['143', '146', '160']},{'id': '143', 'type': 'pattern_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'o_nds'},{'id': '150', 'type': 'conditional_expression', 'children': ['151', '152', '158'], 'value': 'if'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '157'], 'value': '>'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'o_nds'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'list', 'children': ['159'], 'value': '[res]'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'if_statement', 'children': ['162', '169']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '166'], 'value': 'and'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'in'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'output_nodes'},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'is'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'True', 'children': []}
def _set_function_node_output(self, node_id, node_attr, no_call, next_nds=None, **kw): o_nds, dist = node_attr['outputs'], self.dist output_nodes = next_nds or set(self._succ[node_id]).difference(dist) if not output_nodes: self.workflow.remove_node(node_id) return False wf_add_edge = self._wf_add_edge if no_call: for u in output_nodes: wf_add_edge(node_id, u) return True args = self._wf_pred[node_id] args = [args[k]['value'] for k in node_attr['inputs']] try: self._check_function_domain(args, node_attr, node_id) res = async_thread(self, args, node_attr, node_id, **kw) self.workflow.node[node_id]['results'] = res except SkipNode: return False for k, v in zip(o_nds, res if len(o_nds) > 1 else [res]): if k in output_nodes and v is not NONE: wf_add_edge(node_id, k, value=v) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_initial_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '9', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '36', '48', '60', '66', '77', '88', '96', '103', '111', '119', '127', '268', '274', '326']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '26']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'edge_weight'},{'id': '26', 'type': 'expression_list', 'children': ['27', '30', '33']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_edge_length'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'wf_remove_edge'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'check_wait_in'},{'id': '41', 'type': 'expression_list', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_wf_remove_edge'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'check_wait_in'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dsp_in'},{'id': '53', 'type': 'expression_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_wf_add_edge'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_set_sub_dsp_node_input'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'update_view'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_update_meeting'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '93'], 'value': 'or'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'not'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'False', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '110', 'type': 'string', 'children': [], 'value': "'wait_inputs'"},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '114', 'type': 'subscript', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '118', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'START'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '125', 'type': 'dictionary_splat', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'if_statement', 'children': ['128', '133']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'in'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_wildcards'},{'id': '133', 'type': 'block', 'children': ['134', '143', '152', '266']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_visited'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'workflow'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '152', 'type': 'for_statement', 'children': ['153', '156', '165']},{'id': '153', 'type': 'pattern_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '156', 'type': 'call', 'children': ['157', '164']},{'id': '157', 'type': 'attribute', 'children': ['158', '163']},{'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': 'dmap'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'block', 'children': ['166', '174', '180', '190', '196', '234', '240', '253']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'wf_add_edge'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '172', 'type': 'dictionary_splat', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'edge_weight'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'update_view'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '196', 'type': 'if_statement', 'children': ['197', '201', '209', '226']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '201', 'type': 'block', 'children': ['202', '208']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'wf_remove_edge'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '208', 'type': 'continue_statement', 'children': []},{'id': '209', 'type': 'elif_clause', 'children': ['210', '215']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': '=='},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '213', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '214', 'type': 'string', 'children': [], 'value': "'dispatcher'"},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'dsp_in'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222', '223', '224', '225']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'no_call'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '226', 'type': 'elif_clause', 'children': ['227', '232']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'check_wait_in'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'True', 'children': []},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'continue_statement', 'children': []},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '243', 'type': 'tuple', 'children': ['244', '245', '246']},{'id': '244', 'type': 'True', 'children': []},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '250'], 'value': '+'},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '252', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'heappush'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '260', 'type': 'tuple', 'children': ['261', '262', '263']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'vw_dist'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '263', 'type': 'tuple', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'return_statement', 'children': ['267']},{'id': '267', 'type': 'True', 'children': []},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'update_view'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '274', 'type': 'if_statement', 'children': ['275', '279', '286']},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'check_cutoff'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'wf_remove_edge'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'START'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '286', 'type': 'elif_clause', 'children': ['287', '293']},{'id': '287', 'type': 'not_operator', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'check_wait_in'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '293', 'type': 'block', 'children': ['294', '300', '311', '324']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '303', 'type': 'tuple', 'children': ['304', '305', '306']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '306', 'type': 'binary_operator', 'children': ['307', '310'], 'value': '+'},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'heappush'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '318', 'type': 'tuple', 'children': ['319', '320', '321']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'initial_dist'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '321', 'type': 'tuple', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'data_id'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '324', 'type': 'return_statement', 'children': ['325']},{'id': '325', 'type': 'True', 'children': []},{'id': '326', 'type': 'return_statement', 'children': ['327']},{'id': '327', 'type': 'False', 'children': []}
def _add_initial_value(self, data_id, value, initial_dist=0.0, fringe=None, check_cutoff=None, no_call=None): nodes, seen, edge_weight = self.nodes, self.seen, self._edge_length wf_remove_edge, check_wait_in = self._wf_remove_edge, self.check_wait_in wf_add_edge, dsp_in = self._wf_add_edge, self._set_sub_dsp_node_input update_view = self._update_meeting if fringe is None: fringe = self.fringe if no_call is None: no_call = self.no_call check_cutoff = check_cutoff or self.check_cutoff if data_id not in nodes: return False wait_in = nodes[data_id]['wait_inputs'] index = nodes[data_id]['index'] wf_add_edge(START, data_id, **value) if data_id in self._wildcards: self._visited.add(data_id) self.workflow.add_node(data_id) for w, edge_data in self.dmap[data_id].items(): wf_add_edge(data_id, w, **value) node = nodes[w] vw_dist = initial_dist + edge_weight(edge_data, node) update_view(w, vw_dist) if check_cutoff(vw_dist): wf_remove_edge(data_id, w) continue elif node['type'] == 'dispatcher': dsp_in(data_id, w, fringe, check_cutoff, no_call, vw_dist) elif check_wait_in(True, w): continue seen[w] = vw_dist vd = (True, w, self.index + node['index']) heapq.heappush(fringe, (vw_dist, vd, (w, self))) return True update_view(data_id, initial_dist) if check_cutoff(initial_dist): wf_remove_edge(START, data_id) elif not check_wait_in(wait_in, data_id): seen[data_id] = initial_dist vd = (wait_in, data_id, self.index + index) heapq.heappush(fringe, (initial_dist, vd, (data_id, self))) return True return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_see_node'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'w_wait_in'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12', '24', '34', '42', '132']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '17', 'type': 'expression_list', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '27', 'type': 'subscript', 'children': ['28', '33']},{'id': '28', 'type': 'subscript', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '33', 'type': 'string', 'children': [], 'value': "'wait_inputs'"},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_update_meeting'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '42', 'type': 'if_statement', 'children': ['43', '50', '52', '74']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'check_wait_in'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'pass_statement', 'children': []},{'id': '52', 'type': 'elif_clause', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'in'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '63']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '<'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'DispatcherError'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'concatenated_string', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'Contradictory paths found: '"},{'id': '70', 'type': 'string', 'children': [], 'value': "'negative weights?'"},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sol'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'elif_clause', 'children': ['75', '84']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '79'], 'value': 'or'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'not'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '<'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '84', 'type': 'block', 'children': ['85', '91', '101', '117', '130']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '94', 'type': 'subscript', 'children': ['95', '100']},{'id': '95', 'type': 'subscript', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '100', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '104', 'type': 'tuple', 'children': ['105', '111', '112']},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'w_wait_in'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'wait_in'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '116'], 'value': '+'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'heapq'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'heappush'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '124', 'type': 'tuple', 'children': ['125', '126', '127']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'vd'},{'id': '127', 'type': 'tuple', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'True', 'children': []},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'False', 'children': []}
def _see_node(self, node_id, fringe, dist, w_wait_in=0): seen, dists = self.seen, self.dist wait_in = self.nodes[node_id]['wait_inputs'] self._update_meeting(node_id, dist) if self.check_wait_in(wait_in, node_id): pass elif node_id in dists: if dist < dists[node_id]: raise DispatcherError('Contradictory paths found: ' 'negative weights?', sol=self) elif node_id not in seen or dist < seen[node_id]: seen[node_id] = dist index = self.nodes[node_id]['index'] vd = (w_wait_in + int(wait_in), node_id, self.index + index) heapq.heappush(fringe, (dist, vd, (node_id, self))) return True return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tick'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '6', 'type': 'block', 'children': ['7', '13', '71', '274', '278', '402']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'add_new_threads'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '17', 'type': 'block', 'children': ['18', '30', '38', '48']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'tuple_pattern', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'my'},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'screen'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_mouse_pos'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'tuple_pattern', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ox'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'oy'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'drag_offset'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'new_position'},{'id': '41', 'type': 'tuple', 'children': ['42', '45']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ox'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'my'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'oy'},{'id': '48', 'type': 'if_statement', 'children': ['49', '56']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '55'], 'value': '!='},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'new_position'},{'id': '56', 'type': 'block', 'children': ['57', '63']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'has_dragged'},{'id': '62', 'type': 'True', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', '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': 'drag_sprite'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'new_position'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '81', '108', '240']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '=='},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '80', 'type': 'string', 'children': [], 'value': '"key_pressed"'},{'id': '81', 'type': 'block', 'children': ['82', '98']},{'id': '82', 'type': 'assert_statement', 'children': ['83']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': 'in'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '87', 'type': 'call', 'children': ['88', '97']},{'id': '88', 'type': 'attribute', 'children': ['89', '96']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'kurt'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Insert'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'string', 'children': [], 'value': '"key"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'trigger_hats'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"whenKeyPressed"'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '108', 'type': 'elif_clause', 'children': ['109', '114']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '113', 'type': 'string', 'children': [], 'value': '"mouse_down"'},{'id': '114', 'type': 'block', 'children': ['115', '125', '176']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mouse_pos'},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'screen'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_mouse_pos'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'for_statement', 'children': ['126', '127', '135', '166']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sprites'},{'id': '135', 'type': 'block', 'children': ['136', '143']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bounds'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '143', 'type': 'if_statement', 'children': ['144', '150']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'collide_point'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mouse_pos'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'if_statement', 'children': ['152', '160']},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'screen'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'touching_mouse'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '160', 'type': 'block', 'children': ['161', '165']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '165', 'type': 'break_statement', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'stage'},{'id': '176', 'type': 'if_statement', 'children': ['177', '180', '230']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'is_draggable'},{'id': '180', 'type': 'block', 'children': ['181', '193', '201', '213', '219', '225']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '186']},{'id': '183', 'type': 'tuple_pattern', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'my'},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'screen'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'get_mouse_pos'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'tuple_pattern', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'drag_offset'},{'id': '206', 'type': 'tuple', 'children': ['207', '210']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '-'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'mx'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '-'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'my'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'has_dragged'},{'id': '224', 'type': 'False', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'go_to_front'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'trigger_scriptable_hats'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '239', 'type': 'string', 'children': [], 'value': '"whenClicked"'},{'id': '240', 'type': 'elif_clause', 'children': ['241', '246']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '245'], 'value': '=='},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '245', 'type': 'string', 'children': [], 'value': '"mouse_up"'},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'if_statement', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '251', 'type': 'block', 'children': ['252', '268']},{'id': '252', 'type': 'if_statement', 'children': ['253', '257']},{'id': '253', 'type': 'not_operator', 'children': ['254']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'has_dragged'},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'trigger_scriptable_hats'},{'id': '263', 'type': 'argument_list', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '267', 'type': 'string', 'children': [], 'value': '"whenClicked"'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'drag_sprite'},{'id': '273', 'type': 'None', 'children': []},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'remove_threads'},{'id': '277', 'type': 'list', 'children': [], 'value': '[]'},{'id': '278', 'type': 'while_statement', 'children': ['279', '280']},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'for_statement', 'children': ['282', '285', '292', '399']},{'id': '282', 'type': 'tuple_pattern', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '291', 'type': 'argument_list', 'children': []},{'id': '292', 'type': 'block', 'children': ['293', '297', '395']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '296', 'type': 'False', 'children': []},{'id': '297', 'type': 'for_statement', 'children': ['298', '299', '304']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'tick'},{'id': '303', 'type': 'argument_list', 'children': []},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'if_statement', 'children': ['306', '311', '390']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '=='},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '310', 'type': 'string', 'children': [], 'value': '"stop"'},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'if_statement', 'children': ['313', '318', '326', '371']},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '317'], 'value': '=='},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '317', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '318', 'type': 'block', 'children': ['319', '325']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '324', 'type': 'argument_list', 'children': []},{'id': '325', 'type': 'return_statement', 'children': []},{'id': '326', 'type': 'elif_clause', 'children': ['327', '332']},{'id': '327', 'type': 'comparison_operator', 'children': ['328', '331'], 'value': '=='},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '331', 'type': 'string', 'children': [], 'value': '"other scripts in sprite"'},{'id': '332', 'type': 'block', 'children': ['333', '366', '370']},{'id': '333', 'type': 'for_statement', 'children': ['334', '337', '344']},{'id': '334', 'type': 'tuple_pattern', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '337', 'type': 'call', 'children': ['338', '343']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '343', 'type': 'argument_list', 'children': []},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'if_statement', 'children': ['346', '353']},{'id': '346', 'type': 'comparison_operator', 'children': ['347', '350'], 'value': '=='},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'scriptable'},{'id': '353', 'type': 'block', 'children': ['354', '360']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '359', 'type': 'argument_list', 'children': []},{'id': '360', 'type': 'delete_statement', 'children': ['361']},{'id': '361', 'type': 'subscript', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'assignment', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '369', 'type': 'True', 'children': []},{'id': '370', 'type': 'break_statement', 'children': []},{'id': '371', 'type': 'else_clause', 'children': ['372']},{'id': '372', 'type': 'block', 'children': ['373', '379', '385', '389']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '378', 'type': 'argument_list', 'children': []},{'id': '379', 'type': 'delete_statement', 'children': ['380']},{'id': '380', 'type': 'subscript', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'assignment', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '388', 'type': 'True', 'children': []},{'id': '389', 'type': 'break_statement', 'children': []},{'id': '390', 'type': 'else_clause', 'children': ['391']},{'id': '391', 'type': 'block', 'children': ['392']},{'id': '392', 'type': 'expression_statement', 'children': ['393']},{'id': '393', 'type': 'yield', 'children': ['394']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '395', 'type': 'if_statement', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '397', 'type': 'block', 'children': ['398']},{'id': '398', 'type': 'break_statement', 'children': []},{'id': '399', 'type': 'else_clause', 'children': ['400']},{'id': '400', 'type': 'block', 'children': ['401']},{'id': '401', 'type': 'break_statement', 'children': []},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'call', 'children': ['404', '407']},{'id': '404', 'type': 'attribute', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'add_new_threads'},{'id': '407', 'type': 'argument_list', 'children': []}
def tick(self, events): self.add_new_threads() if self.drag_sprite: (mx, my) = self.screen.get_mouse_pos() (ox, oy) = self.drag_offset new_position = (mx + ox, my + oy) if self.drag_sprite.position != new_position: self.has_dragged = True self.drag_sprite.position = new_position for event in events: if event.kind == "key_pressed": assert event.value in kurt.Insert(None, "key").options() self.trigger_hats("whenKeyPressed", event.value) elif event.kind == "mouse_down": mouse_pos = self.screen.get_mouse_pos() for sprite in reversed(self.project.sprites): rect = bounds(sprite) if rect.collide_point(mouse_pos): if self.screen.touching_mouse(sprite): scriptable = sprite break else: scriptable = self.project.stage if scriptable.is_draggable: (mx, my) = self.screen.get_mouse_pos() (x, y) = scriptable.position self.drag_offset = (x - mx, y - my) self.drag_sprite = scriptable self.has_dragged = False go_to_front(scriptable) else: self.trigger_scriptable_hats(scriptable, "whenClicked") elif event.kind == "mouse_up": if self.drag_sprite: if not self.has_dragged: self.trigger_scriptable_hats(self.drag_sprite, "whenClicked") self.drag_sprite = None remove_threads = [] while 1: for (script, thread) in self.threads.items(): modified = False for event in thread.tick(): if event.kind == "stop": if event.value == "all": self.stop() return elif event.value == "other scripts in sprite": for (script, other) in self.threads.items(): if other.scriptable == thread.scriptable: other.finish() del self.threads[script] modified = True break else: thread.finish() del self.threads[script] modified = True break else: yield event if modified: break else: break self.add_new_threads()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'evaluate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '29', '208', '414']},{'id': '11', 'type': 'assert_statement', 'children': ['12']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kurt'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Script'},{'id': '20', 'type': 'if_statement', 'children': ['21', '26']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'and'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'unevaluated'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kurt'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Block'},{'id': '37', 'type': 'block', 'children': ['38', '49', '103', '113', '143', '152', '184', '199']},{'id': '38', 'type': 'if_statement', 'children': ['39', '46']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '45'], 'value': '=='},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '45', 'type': 'string', 'children': [], 'value': '"hat"'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'list', 'children': [], 'value': '[]'},{'id': '49', 'type': 'if_statement', 'children': ['50', '57']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': 'not'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'COMMANDS'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '67', '92']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '61', 'type': 'argument_list', 'children': ['62', '65', '66']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '65', 'type': 'string', 'children': [], 'value': "'_workaround'"},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'block', 'children': ['68', '79']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_workaround'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '79', 'type': 'if_statement', 'children': ['80', '82']},{'id': '80', 'type': 'not_operator', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'kurt'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'BlockNotSupported'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'raise_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'kurt'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'BlockNotSupported'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'COMMANDS'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '125']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'evaluate'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'arg_insert'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '129']},{'id': '126', 'type': 'tuple_pattern', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'arg_insert'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '131', 'type': 'argument_list', 'children': ['132', '138']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'inserts'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '150', 'type': 'list_splat', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '152', 'type': 'function_definition', 'children': ['153', '154', '156']},{'id': '153', 'type': 'function_name', 'children': [], 'value': 'flatten_generators'},{'id': '154', 'type': 'parameters', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'gen'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'gen'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'if_statement', 'children': ['162', '168', '179']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'isgenerator'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '175']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'flatten_generators'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'yield', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'yield', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '184', 'type': 'if_statement', 'children': ['185', '191']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isgenerator'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'flatten_generators'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '199', 'type': 'if_statement', 'children': ['200', '203']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'is'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '202', 'type': 'None', 'children': []},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '207', 'type': 'list', 'children': [], 'value': '[]'},{'id': '208', 'type': 'if_statement', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '210', 'type': 'block', 'children': ['211', '260', '281']},{'id': '211', 'type': 'if_statement', 'children': ['212', '217']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '217', 'type': 'block', 'children': ['218', '225']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '225', 'type': 'if_statement', 'children': ['226', '234']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '230'], 'value': 'in'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '230', 'type': 'tuple', 'children': ['231', '232', '233']},{'id': '231', 'type': 'string', 'children': [], 'value': '"number"'},{'id': '232', 'type': 'string', 'children': [], 'value': '"number-menu"'},{'id': '233', 'type': 'string', 'children': [], 'value': '"string"'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'try_statement', 'children': ['236', '244']},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '244', 'type': 'except_clause', 'children': ['245', '248']},{'id': '245', 'type': 'tuple', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'if_statement', 'children': ['250', '255']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': '=='},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '254', 'type': 'string', 'children': [], 'value': '"number"'},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '259', 'type': 'integer', 'children': [], 'value': '0'},{'id': '260', 'type': 'if_statement', 'children': ['261', '273']},{'id': '261', 'type': 'boolean_operator', 'children': ['262', '267'], 'value': 'and'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': '=='},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '281', 'type': 'if_statement', 'children': ['282', '292', '321', '355', '389']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '286'], 'value': 'in'},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '286', 'type': 'tuple', 'children': ['287', '288', '289', '290', '291']},{'id': '287', 'type': 'string', 'children': [], 'value': '"spriteOrStage"'},{'id': '288', 'type': 'string', 'children': [], 'value': '"spriteOrMouse"'},{'id': '289', 'type': 'string', 'children': [], 'value': '"stageOrThis"'},{'id': '290', 'type': 'string', 'children': [], 'value': '"spriteOnly"'},{'id': '291', 'type': 'string', 'children': [], 'value': '"touching"'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'if_statement', 'children': ['294', '299']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': 'not'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '296', 'type': 'tuple', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': '"mouse-pointer"'},{'id': '298', 'type': 'string', 'children': [], 'value': '"edge"'},{'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': 'value'},{'id': '303', 'type': '()', 'children': ['304']},{'id': '304', 'type': 'conditional_expression', 'children': ['305', '310', '313'], 'value': 'if'},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'stage'},{'id': '310', 'type': 'comparison_operator', 'children': ['311', '312'], 'value': '=='},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '312', 'type': 'string', 'children': [], 'value': '"Stage"'},{'id': '313', 'type': 'call', 'children': ['314', '319']},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'get_sprite'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '321', 'type': 'elif_clause', 'children': ['322', '327']},{'id': '322', 'type': 'comparison_operator', 'children': ['323', '326'], 'value': '=='},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '326', 'type': 'string', 'children': [], 'value': '"var"'},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'if_statement', 'children': ['329', '334', '343']},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '331'], 'value': 'in'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '338', 'type': 'subscript', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '343', 'type': 'else_clause', 'children': ['344']},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '348', 'type': 'subscript', 'children': ['349', '354']},{'id': '349', 'type': 'attribute', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '355', 'type': 'elif_clause', 'children': ['356', '361']},{'id': '356', 'type': 'comparison_operator', 'children': ['357', '360'], 'value': '=='},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '360', 'type': 'string', 'children': [], 'value': '"list"'},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'if_statement', 'children': ['363', '368', '377']},{'id': '363', 'type': 'comparison_operator', 'children': ['364', '365'], 'value': 'in'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'lists'},{'id': '368', 'type': 'block', 'children': ['369']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '372', 'type': 'subscript', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'lists'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '377', 'type': 'else_clause', 'children': ['378']},{'id': '378', 'type': 'block', 'children': ['379']},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'assignment', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '382', 'type': 'subscript', 'children': ['383', '388']},{'id': '383', 'type': 'attribute', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'lists'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '389', 'type': 'elif_clause', 'children': ['390', '395']},{'id': '390', 'type': 'comparison_operator', 'children': ['391', '394'], 'value': '=='},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '394', 'type': 'string', 'children': [], 'value': '"sound"'},{'id': '395', 'type': 'block', 'children': ['396']},{'id': '396', 'type': 'for_statement', 'children': ['397', '398', '401']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'sound'},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'sounds'},{'id': '401', 'type': 'block', 'children': ['402']},{'id': '402', 'type': 'if_statement', 'children': ['403', '408']},{'id': '403', 'type': 'comparison_operator', 'children': ['404', '407'], 'value': '=='},{'id': '404', 'type': 'attribute', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'sound'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '408', 'type': 'block', 'children': ['409', '413']},{'id': '409', 'type': 'expression_statement', 'children': ['410']},{'id': '410', 'type': 'assignment', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'sound'},{'id': '413', 'type': 'break_statement', 'children': []},{'id': '414', 'type': 'return_statement', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'value'}
def evaluate(self, s, value, insert=None): assert not isinstance(value, kurt.Script) if insert and insert.unevaluated: return value if isinstance(value, kurt.Block): if value.type.shape == "hat": return [] if value.type not in self.COMMANDS: if getattr(value.type, '_workaround', None): value = value.type._workaround(value) if not value: raise kurt.BlockNotSupported(value.type) else: raise kurt.BlockNotSupported(value.type) f = self.COMMANDS[value.type] args = [self.evaluate(s, arg, arg_insert) for (arg, arg_insert) in zip(list(value.args), value.type.inserts)] value = f(s, *args) def flatten_generators(gen): for item in gen: if inspect.isgenerator(item): for x in flatten_generators(item): yield x else: yield item if inspect.isgenerator(value): value = flatten_generators(value) if value is None: value = [] if insert: if isinstance(value, basestring): value = unicode(value) if insert.shape in ("number", "number-menu", "string"): try: value = float(value) except (TypeError, ValueError): if insert.shape == "number": value = 0 if isinstance(value, float) and value == int(value): value = int(value) if insert.kind in ("spriteOrStage", "spriteOrMouse", "stageOrThis", "spriteOnly", "touching"): if value not in ("mouse-pointer", "edge"): value = (self.project.stage if value == "Stage" else self.project.get_sprite(value)) elif insert.kind == "var": if value in s.variables: value = s.variables[value] else: value = s.project.variables[value] elif insert.kind == "list": if value in s.lists: value = s.lists[value] else: value = s.project.lists[value] elif insert.kind == "sound": for sound in s.sounds: if sound.name == value: value = sound break return value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_write'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'maskMap'},{'id': '8', 'type': 'block', 'children': ['9', '13', '20', '80', '94', '108', '122', '136', '140', '200', '269']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'FIRST_VALUE_INDEX'},{'id': '12', 'type': 'integer', 'children': [], 'value': '12'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'DATASET\\r\\n'"},{'id': '20', 'type': 'if_statement', 'children': ['21', '28', '50']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '=='},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'SCALAR_TYPE'},{'id': '28', 'type': 'block', 'children': ['29', '43']},{'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': 'openFile'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'OBJTYPE {0}\\r\\n'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'objectType'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'BEGSCL\\r\\n'"},{'id': '50', 'type': 'elif_clause', 'children': ['51', '58']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'VECTOR_TYPE'},{'id': '58', 'type': 'block', 'children': ['59', '73']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'VECTYPE {0}\\r\\n'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'},{'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': 'vectorType'},{'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': 'openFile'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'BEGVEC\\r\\n'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'OBJID {0}\\r\\n'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'objectID'},{'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': 'openFile'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'ND {0}\\r\\n'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'numberData'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'NC {0}\\r\\n'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'numberCells'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'NAME {0}\\r\\n'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'statusString'},{'id': '139', 'type': 'string', 'children': [], 'value': "''"},{'id': '140', 'type': 'if_statement', 'children': ['141', '146']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'maskMap'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'RasterMapFile'},{'id': '146', 'type': 'block', 'children': ['147', '156', '181']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'statusGrassRasterString'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'maskMap'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'getAsGrassAsciiGrid'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '156', 'type': 'if_statement', 'children': ['157', '160', '169']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'statusGrassRasterString'},{'id': '159', 'type': 'None', 'children': []},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'statusValues'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'statusGrassRasterString'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'else_clause', 'children': ['170']},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'statusValues'},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'maskMap'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'rasterText'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '191']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'FIRST_VALUE_INDEX'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'statusValues'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'augmented_assignment', 'children': ['194', '195'], 'value': '+='},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'statusString'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '199'], 'value': '+'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'statusValues'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'string', 'children': [], 'value': "'\\r\\n'"},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '205']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'rasters'},{'id': '205', 'type': 'block', 'children': ['206', '223', '237', '246']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'TS {0} {1}\\r\\n'"},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'iStatus'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '223', 'type': 'if_statement', 'children': ['224', '229']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '228'], 'value': '=='},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'iStatus'},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'openFile'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'statusString'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'getAsWmsDatasetString'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '246', 'type': 'if_statement', 'children': ['247', '250', '258']},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'is'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '249', 'type': 'None', 'children': []},{'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': 'openFile'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'valueString'},{'id': '258', 'type': 'else_clause', 'children': ['259']},{'id': '259', 'type': 'block', 'children': ['260']},{'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': 'openFile'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'timeStepRaster'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'rasterText'},{'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': 'openFile'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'string', 'children': [], 'value': "'ENDDS\\r\\n'"}
def _write(self, session, openFile, maskMap): FIRST_VALUE_INDEX = 12 openFile.write('DATASET\r\n') if self.type == self.SCALAR_TYPE: openFile.write('OBJTYPE {0}\r\n'.format(self.objectType)) openFile.write('BEGSCL\r\n') elif self.type == self.VECTOR_TYPE: openFile.write('VECTYPE {0}\r\n'.format(self.vectorType)) openFile.write('BEGVEC\r\n') openFile.write('OBJID {0}\r\n'.format(self.objectID)) openFile.write('ND {0}\r\n'.format(self.numberData)) openFile.write('NC {0}\r\n'.format(self.numberCells)) openFile.write('NAME {0}\r\n'.format(self.name)) statusString = '' if isinstance(maskMap, RasterMapFile): statusGrassRasterString = maskMap.getAsGrassAsciiGrid(session) if statusGrassRasterString is not None: statusValues = statusGrassRasterString.split() else: statusValues = maskMap.rasterText.split() for i in range(FIRST_VALUE_INDEX, len(statusValues)): statusString += statusValues[i] + '\r\n' for timeStepRaster in self.rasters: openFile.write('TS {0} {1}\r\n'.format(timeStepRaster.iStatus, timeStepRaster.timestamp)) if timeStepRaster.iStatus == 1: openFile.write(statusString) valueString = timeStepRaster.getAsWmsDatasetString(session) if valueString is not None: openFile.write(valueString) else: openFile.write(timeStepRaster.rasterText) openFile.write('ENDDS\r\n')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_batch'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'token_dict'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_case'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'unk_index'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'eos_index'},{'id': '14', 'type': 'integer', 'children': [], 'value': '2'},{'id': '15', 'type': 'block', 'children': ['16', '23', '34', '48', '62', '76', '189', '207', '225']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_sentence_len'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '37', 'type': 'list_comprehension', 'children': ['38', '42']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '41'], 'value': '*'},{'id': '39', 'type': 'list', 'children': ['40'], 'value': '[0]'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'max_sentence_len'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '51', 'type': 'list_comprehension', 'children': ['52', '56']},{'id': '52', 'type': 'binary_operator', 'children': ['53', '55'], 'value': '*'},{'id': '53', 'type': 'list', 'children': ['54'], 'value': '[0]'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'max_sentence_len'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'},{'id': '65', 'type': 'list_comprehension', 'children': ['66', '70']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '69'], 'value': '*'},{'id': '67', 'type': 'list', 'children': ['68'], 'value': '[0]'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'max_sentence_len'},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'batch_size'},{'id': '76', 'type': 'for_statement', 'children': ['77', '80', '84']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sentences'},{'id': '84', 'type': 'block', 'children': ['85', '98', '106']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '97']},{'id': '87', 'type': 'subscript', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '96'], 'value': '-'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'eos_index'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '105']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'eos_index'},{'id': '106', 'type': 'for_statement', 'children': ['107', '110', '114']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'token'},{'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': 'sentence'},{'id': '114', 'type': 'block', 'children': ['115', '144', '152', '169']},{'id': '115', 'type': 'if_statement', 'children': ['116', '117', '132']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ignore_case'},{'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': 'index'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'token_dict'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '125', 'type': 'argument_list', 'children': ['126', '131']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'unk_index'},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'token_dict'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'unk_index'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '151']},{'id': '146', 'type': 'subscript', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '152', 'type': 'if_statement', 'children': ['153', '158']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': '>='},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '-'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '168']},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '-'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '169', 'type': 'if_statement', 'children': ['170', '178']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '<'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'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', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'expand_dims'},{'id': '196', 'type': 'argument_list', 'children': ['197', '203']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '205', 'type': 'unary_operator', 'children': ['206'], 'value': '-'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'expand_dims'},{'id': '214', 'type': 'argument_list', 'children': ['215', '221']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '223', 'type': 'unary_operator', 'children': ['224'], 'value': '-'},{'id': '224', 'type': 'integer', 'children': [], 'value': '1'},{'id': '225', 'type': 'return_statement', 'children': ['226']},{'id': '226', 'type': 'expression_list', 'children': ['227', '233']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '233', 'type': 'list', 'children': ['234', '235'], 'value': '[outputs_forward, outputs_backward]'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'outputs_forward'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'outputs_backward'}
def get_batch(sentences, token_dict, ignore_case=False, unk_index=1, eos_index=2): batch_size = len(sentences) max_sentence_len = max(map(len, sentences)) inputs = [[0] * max_sentence_len for _ in range(batch_size)] outputs_forward = [[0] * max_sentence_len for _ in range(batch_size)] outputs_backward = [[0] * max_sentence_len for _ in range(batch_size)] for i, sentence in enumerate(sentences): outputs_forward[i][len(sentence) - 1] = eos_index outputs_backward[i][0] = eos_index for j, token in enumerate(sentence): if ignore_case: index = token_dict.get(token.lower(), unk_index) else: index = token_dict.get(token, unk_index) inputs[i][j] = index if j - 1 >= 0: outputs_forward[i][j - 1] = index if j + 1 < len(sentence): outputs_backward[i][j + 1] = index outputs_forward = np.expand_dims(np.asarray(outputs_forward), axis=-1) outputs_backward = np.expand_dims(np.asarray(outputs_backward), axis=-1) return np.asarray(inputs), [outputs_forward, outputs_backward]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_gene_info'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ensembl_ids'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbols'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '24', '37', '41', '45', '134', '211']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'uniq_ensembl_ids'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '16', 'type': 'generator_expression', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'or'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ensembl_ids'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'uniq_hgnc_symbols'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '29', 'type': 'generator_expression', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '33', 'type': '()', 'children': ['34']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '36'], 'value': 'or'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbols'},{'id': '36', 'type': 'list', 'children': [], 'value': '[]'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'gene_data'},{'id': '44', 'type': 'list', 'children': [], 'value': '[]'},{'id': '45', 'type': 'if_statement', 'children': ['46', '47', '68']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'uniq_ensembl_ids'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'uniq_ensembl_ids'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '60']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'query_gene'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'gene_data'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '68', 'type': 'elif_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'uniq_hgnc_symbols'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'uniq_hgnc_symbols'},{'id': '74', 'type': 'block', 'children': ['75', '84']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'query_res'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'query_gene'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '84', 'type': 'if_statement', 'children': ['85', '86', '98']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'query_res'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'query_res'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'gene_data'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '98', 'type': 'else_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'gene_data'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'dictionary', 'children': ['107', '110', '113', '116', '119', '122', '125', '128', '131']},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'hgnc_symbol'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'hgnc_symbol'},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'hgnc_id'"},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'ensembl_id'"},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'pair', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'pair', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "'chrom'"},{'id': '121', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '122', 'type': 'pair', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'stop'"},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'pair', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'hi_score'"},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'constraint_score'"},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '137']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'gene_data'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'Gene'},{'id': '146', 'type': 'argument_list', 'children': ['147', '152', '157', '162', '167', '172', '177', '182', '193', '198', '203']},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '151', 'type': 'string', 'children': [], 'value': "'hgnc_symbol'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '156', 'type': 'string', 'children': [], 'value': "'hgnc_id'"},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ensembl_id'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '161', 'type': 'string', 'children': [], 'value': "'ensembl_id'"},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '166', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '171', 'type': 'string', 'children': [], 'value': "'chrom'"},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '176', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '181', 'type': 'string', 'children': [], 'value': "'stop'"},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get_cytoband_coord'},{'id': '186', 'type': 'argument_list', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '189', 'type': 'string', 'children': [], 'value': "'chrom'"},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '192', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'hi_score'},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '197', 'type': 'string', 'children': [], 'value': "'hi_score'"},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'constraint_score'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '202', 'type': 'string', 'children': [], 'value': "'constraint_score'"},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'omim_number'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'get_omim_number'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '210', 'type': 'string', 'children': [], 'value': "'hgnc_symbol'"},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'genes'}
def get_gene_info(ensembl_ids=None, hgnc_symbols=None): uniq_ensembl_ids = set(ensembl_id for ensembl_id in (ensembl_ids or [])) uniq_hgnc_symbols = set(hgnc_symbol for hgnc_symbol in (hgnc_symbols or [])) genes = [] gene_data = [] if uniq_ensembl_ids: for ensembl_id in uniq_ensembl_ids: for res in query_gene(ensembl_id=ensembl_id): gene_data.append(res) elif uniq_hgnc_symbols: for hgnc_symbol in uniq_hgnc_symbols: query_res = query_gene(hgnc_symbol=hgnc_symbol) if query_res: for res in query_res: gene_data.append(res) else: gene_data.append({ 'hgnc_symbol': hgnc_symbol, 'hgnc_id': None, 'ensembl_id': None, 'description': None, 'chrom': 'unknown', 'start': 0, 'stop': 0, 'hi_score': None, 'constraint_score': None, }) for gene in gene_data: genes.append(Gene( symbol=gene ['hgnc_symbol'], hgnc_id=gene['hgnc_id'], ensembl_id=gene['ensembl_id'], description=gene['description'], chrom=gene['chrom'], start=gene['start'], stop=gene['stop'], location=get_cytoband_coord(gene['chrom'], gene['start']), hi_score=gene['hi_score'], constraint_score=gene['constraint_score'], omim_number=get_omim_number(gene['hgnc_symbol']) )) return genes
{'id': '0', 'type': 'module', 'children': ['1', '13', '17', '29', '33', '42', '46', '60', '109', '121', '135', '146', '150', '376']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_mapping'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': [], 'value': ''},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'include_re'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'include_re'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'include_re'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mapping_re'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mapping_re'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mapping_re'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '60', 'type': 'if_statement', 'children': ['61', '67', '72']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'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': 'filename'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '72', 'type': 'elif_clause', 'children': ['73', '79']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '85']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'map_name'},{'id': '82', 'type': 'expression_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'.dotfiles'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'dotfiles'"},{'id': '85', 'type': 'block', 'children': ['86', '96']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'map_name'},{'id': '96', 'type': 'if_statement', 'children': ['97', '103']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '103', 'type': 'block', 'children': ['104', '108']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '108', 'type': 'break_statement', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'raise_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '%'},{'id': '119', 'type': 'string', 'children': [], 'value': "'No dotfile mapping found in %s'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'map_path'},{'id': '135', 'type': 'if_statement', 'children': ['136', '139']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'is'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'with_statement', 'children': ['151', '160']},{'id': '151', 'type': 'with_clause', 'children': ['152']},{'id': '152', 'type': 'with_item', 'children': ['153']},{'id': '153', 'type': 'as_pattern', 'children': ['154', '158']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '158', 'type': 'as_pattern_target', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '164', 'type': 'block', 'children': ['165', '169', '177', '186', '296']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'augmented_assignment', 'children': ['167', '168'], 'value': '+='},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'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': 'content'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'include_re'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '186', 'type': 'if_statement', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '188', 'type': 'block', 'children': ['189', '203', '250']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '192', 'type': 'call', 'children': ['193', '201']},{'id': '193', 'type': 'attribute', 'children': ['194', '200']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'integer', 'children': [], 'value': '1'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': '\'\\\'"\''},{'id': '203', 'type': 'if_statement', 'children': ['204', '218', '233']},{'id': '204', 'type': '()', 'children': ['205']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '212'], 'value': 'or'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '233', 'type': 'else_clause', 'children': ['234']},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '242', 'type': 'argument_list', 'children': ['243', '249']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '250', 'type': 'if_statement', 'children': ['251', '257', '280']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '257', 'type': 'block', 'children': ['258', '268']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '265']},{'id': '260', 'type': 'attribute', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'Recursively parsing mapping in %s'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'parse_mapping'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '289']},{'id': '284', 'type': 'attribute', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '289', 'type': 'argument_list', 'children': ['290', '294', '295']},{'id': '290', 'type': 'concatenated_string', 'children': ['291', '292', '293']},{'id': '291', 'type': 'string', 'children': [], 'value': "'Include command points to file or '"},{'id': '292', 'type': 'string', 'children': [], 'value': '\'directory that does not exist, "%s",\''},{'id': '293', 'type': 'string', 'children': [], 'value': "' on line %d'"},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'include_path'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '296', 'type': 'if_statement', 'children': ['297', '303', '313', '367']},{'id': '297', 'type': 'boolean_operator', 'children': ['298', '300'], 'value': 'or'},{'id': '298', 'type': 'not_operator', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '303', 'type': 'ERROR', 'children': ['304', '306', '312']},{'id': '304', 'type': 'ERROR', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'mapping_re'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '313', 'type': 'block', 'children': ['314', '324', '339', '361']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '319']},{'id': '316', 'type': 'pattern_list', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'target_path'},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '331', 'type': 'argument_list', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'string', 'children': [], 'value': '\'\\\'"\''},{'id': '339', 'type': 'if_statement', 'children': ['340', '343', '356']},{'id': '340', 'type': 'comparison_operator', 'children': ['341', '342'], 'value': 'in'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '343', 'type': 'ERROR', 'children': ['344', '349', '350', '353']},{'id': '344', 'type': 'attribute', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '349', 'type': 'string', 'children': [], 'value': '\'Duplicate dotfile source "%s" \''},{'id': '350', 'type': 'ERROR', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'on'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '353', 'type': 'comparison_operator', 'children': ['354', '355'], 'value': 'is'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'target_path'},{'id': '355', 'type': 'None', 'children': []},{'id': '356', 'type': 'block', 'children': ['357']},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'assignment', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'target_path'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '366']},{'id': '363', 'type': 'subscript', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'dotfiles'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'target_path'},{'id': '367', 'type': 'else_clause', 'children': ['368', '375']},{'id': '368', 'type': 'ERROR', 'children': ['369', '374']},{'id': '369', 'type': 'attribute', 'children': ['370', '373']},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '374', 'type': 'string', 'children': [], 'value': "'Dotfile mapping regex failed on line '"},{'id': '375', 'type': 'block', 'children': [], 'value': ''},{'id': '376', 'type': 'return_statement', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'dotfiles'}
def parse_mapping(self, map_path, source=None, dotfiles=None): include_re = r include_re = re.compile(include_re, re.I) mapping_re = r mapping_re = re.compile(mapping_re) filename = None map_path = path.realpath(path.expanduser(map_path)) if path.isfile(map_path): filename = map_path elif path.isdir(map_path): for map_name in '.dotfiles', 'dotfiles': candidate = path.join(map_path, map_name) if path.isfile(candidate): filename = candidate break if filename is None: raise ValueError('No dotfile mapping found in %s' % map_path) if source is None: source = path.dirname(map_path) if dotfiles is None: dotfiles = OrderedDict() lineno = 0 with open(filename) as fh: for line in fh: lineno += 1 content = line.strip() match = include_re.match(content) if match: include_path = match.group(1).strip('\'"') if (include_path.startswith('/') or include_path.startswith('~')): include_path = path.realpath( path.expanduser(include_path)) else: include_path = path.join(path.dirname(filename), include_path) if path.exists(include_path): self.log.debug('Recursively parsing mapping in %s', include_path) dotfiles = self.parse_mapping(include_path, dotfiles=dotfiles) else: self.log.warning('Include command points to file or ' 'directory that does not exist, "%s",' ' on line %d', include_path, lineno) if not content or content.startswith(' continue match = mapping_re.match(content) if match: source_path, target_path = match.groups() source_path = path.join(source, source_path.strip('\'"')) if source_path in dotfiles: self.log.warning('Duplicate dotfile source "%s" ' 'on line continue if target_path is None: target_path = source_path dotfiles[source_path] = target_path else: self.log.warning('Dotfile mapping regex failed on line ' ' return dotfiles
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_compounds'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'info_dict'},{'id': '7', 'type': 'block', 'children': ['8', '12', '21', '106', '123']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'compound_list'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'compound_entry'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'info_dict'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Compounds'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'compound_entry'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '32']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'family_annotation'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'compound_entry'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "','"},{'id': '32', 'type': 'block', 'children': ['33', '50']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'compounds'},{'id': '36', 'type': 'call', 'children': ['37', '48']},{'id': '37', 'type': 'attribute', 'children': ['38', '47']},{'id': '38', 'type': 'subscript', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'family_annotation'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "':'"},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'compound'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'compounds'},{'id': '53', 'type': 'block', 'children': ['54', '63', '67', '91']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'splitted_compound'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'compound'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'>'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'compound_score'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '74']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '73'], 'value': '>'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'splitted_compound'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'block', 'children': ['75', '81']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'compound_id'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'splitted_compound'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'compound_score'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'splitted_compound'},{'id': '89', 'type': 'unary_operator', 'children': ['90'], 'value': '-'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'compound_list'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Compound'},{'id': '99', 'type': 'argument_list', 'children': ['100', '103']},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'variant_id'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'compound_id'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'combined_score'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'compound_score'},{'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': 'compound_list'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '111', 'type': 'argument_list', 'children': ['112', '120']},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'combined_score'"},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'compound'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'compound_list'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'add_compound'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'compound'}
def _add_compounds(self, variant_obj, info_dict): compound_list = [] compound_entry = info_dict.get('Compounds') if compound_entry: for family_annotation in compound_entry.split(','): compounds = family_annotation.split(':')[-1].split('|') for compound in compounds: splitted_compound = compound.split('>') compound_score = None if len(splitted_compound) > 1: compound_id = splitted_compound[0] compound_score = int(splitted_compound[-1]) compound_list.append(Compound( variant_id=compound_id, combined_score=compound_score ) ) compound_list.sort(key = operator.attrgetter('combined_score'), reverse=True) for compound in compound_list: variant_obj.add_compound(compound)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_xml'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '11', 'type': 'string', 'children': [], 'value': "'UTF-8'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '33', '49']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '19', 'type': 'call', 'children': ['20', '28']},{'id': '20', 'type': 'attribute', 'children': ['21', '27']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lookup'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'streamwriter'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '32', 'type': 'string', 'children': [], 'value': "'xmlcharrefreplace'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '36', 'type': 'argument_list', 'children': ['37', '46']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': '\'<?xml version="1.0" encoding={0} standalone="no"?>\''},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'quoteattr'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '57']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_stream_xml'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fp'}
def dump_xml(props, fp, comment=None, encoding='UTF-8', sort_keys=False): fp = codecs.lookup(encoding).streamwriter(fp, errors='xmlcharrefreplace') print('<?xml version="1.0" encoding={0} standalone="no"?>' .format(quoteattr(encoding)), file=fp) for s in _stream_xml(props, comment, sort_keys): print(s, file=fp)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dumps_xml'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "''"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '17', 'type': 'generator_expression', 'children': ['18', '21']},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '+'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '20', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_stream_xml'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}
def dumps_xml(props, comment=None, sort_keys=False): return ''.join(s + '\n' for s in _stream_xml(props, comment, sort_keys))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gene_list'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '24', '76', '130', '267']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'all_case_ids'},{'id': '11', 'type': 'list_comprehension', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '26', 'type': 'block', 'children': ['27', '38', '60']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'gene_list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'case_ids'},{'id': '41', 'type': 'list_comprehension', 'children': ['42', '45', '54']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'case'},{'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': 'app'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'if_clause', 'children': ['55']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'not'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'integer', 'children': [], 'value': '404'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"gene list not found: {}"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '76', 'type': 'if_statement', 'children': ['77', '82']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'string', 'children': [], 'value': "'download'"},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '82', 'type': 'block', 'children': ['83', '97', '111', '120', '128']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'make_response'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'gene_ids'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'secure_filename'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '"{}.txt"'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': '"attachment; filename={}"'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '127']},{'id': '122', 'type': 'subscript', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '126', 'type': 'string', 'children': [], 'value': "'Content-Disposition'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '130', 'type': 'if_statement', 'children': ['131', '136']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '135', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'if_statement', 'children': ['138', '139', '190']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'list_id'},{'id': '139', 'type': 'block', 'children': ['140', '151']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'case_ids'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'getlist'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': "'case_id'"},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'case_ids'},{'id': '154', 'type': 'block', 'children': ['155', '166']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '166', 'type': 'if_statement', 'children': ['167', '172']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'not'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '172', 'type': 'block', 'children': ['173', '182']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192', '200', '216', '232', '242']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'req_file'},{'id': '195', 'type': 'subscript', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '199', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'new_listid'},{'id': '203', 'type': '()', 'children': ['204']},{'id': '204', 'type': 'boolean_operator', 'children': ['205', '210'], 'value': 'or'},{'id': '205', 'type': 'subscript', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '209', 'type': 'string', 'children': [], 'value': "'list_id'"},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'secure_filename'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'req_file'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '216', 'type': 'if_statement', 'children': ['217', '225']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'gene_list'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'new_listid'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'return_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'integer', 'children': [], 'value': '500'},{'id': '231', 'type': 'string', 'children': [], 'value': "'Please provide a unique list name'"},{'id': '232', 'type': 'if_statement', 'children': ['233', '235']},{'id': '233', 'type': 'not_operator', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'req_file'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'integer', 'children': [], 'value': '500'},{'id': '241', 'type': 'string', 'children': [], 'value': "'Please provide a file for upload'"},{'id': '242', 'type': 'ERROR', 'children': ['243', '244', '245', '250', '253', '254', '265', '266']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'gene_ids'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '245', 'type': 'for_in_clause', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'req_file'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '253', 'type': 'ERROR', 'children': []},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '256', 'type': 'call', 'children': ['257', '262']},{'id': '257', 'type': 'attribute', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'add_genelist'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'new_listid'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'gene_ids'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'case_ids'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'all_case_ids'},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'render_template'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272', '275']},{'id': '271', 'type': 'string', 'children': [], 'value': "'gene_list.html'"},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'gene_list'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'genelist_obj'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'case_ids'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'case_ids'}
def gene_list(list_id=None): all_case_ids = [case.case_id for case in app.db.cases()] if list_id: genelist_obj = app.db.gene_list(list_id) case_ids = [case.case_id for case in app.db.cases() if case not in genelist_obj.cases] if genelist_obj is None: return abort(404, "gene list not found: {}".format(list_id)) if 'download' in request.args: response = make_response('\n'.join(genelist_obj.gene_ids)) filename = secure_filename("{}.txt".format(genelist_obj.list_id)) header = "attachment; filename={}".format(filename) response.headers['Content-Disposition'] = header return response if request.method == 'POST': if list_id: case_ids = request.form.getlist('case_id') for case_id in case_ids: case_obj = app.db.case(case_id) if case_obj not in genelist_obj.cases: genelist_obj.cases.append(case_obj) app.db.save() else: req_file = request.files['file'] new_listid = (request.form['list_id'] or secure_filename(req_file.filename)) if app.db.gene_list(new_listid): return abort(500, 'Please provide a unique list name') if not req_file: return abort(500, 'Please provide a file for upload') gene_ids = [line for line in req_file.stream if not line.startswith(' genelist_obj = app.db.add_genelist(new_listid, gene_ids) case_ids = all_case_ids return render_template('gene_list.html', gene_list=genelist_obj, case_ids=case_ids)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_functarguments'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '5', 'type': 'block', 'children': ['6', '15', '75', '91', '97', '101', '108', '153', '288']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getargspec'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '15', 'type': 'if_statement', 'children': ['16', '21', '63']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'is'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '38']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '29', 'type': 'slice', 'children': ['30', '31']},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '46', 'type': 'argument_list', 'children': ['47', '60']},{'id': '47', 'type': 'subscript', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '51', 'type': 'slice', 'children': ['52', '59']},{'id': '52', 'type': 'unary_operator', 'children': ['53'], 'value': '-'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '59', 'type': 'colon', 'children': []},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65', '71']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '74', 'type': 'dictionary', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '83']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '78'], 'value': 'and'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'string', 'children': [], 'value': "'self'"},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__named__'},{'id': '96', 'type': 'list', 'children': [], 'value': '[]'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '100', 'type': 'list', 'children': [], 'value': '[]'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'get_shared'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'block', 'children': ['112', '122', '134', '144']},{'id': '112', 'type': 'if_statement', 'children': ['113', '120']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '119'], 'value': 'is'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'has_shared'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '119', 'type': 'False', 'children': []},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'continue_statement', 'children': []},{'id': '122', 'type': 'if_statement', 'children': ['123', '132']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '131'], 'value': 'is'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'has_argument'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '131', 'type': 'False', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'continue_statement', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'tuple', 'children': ['141', '143']},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[arg]'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '143', 'type': 'dictionary', 'children': []},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '__named__'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '153', 'type': 'for_statement', 'children': ['154', '157', '162']},{'id': '154', 'type': 'pattern_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'block', 'children': ['163', '173', '185', '270', '279']},{'id': '163', 'type': 'if_statement', 'children': ['164', '171']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '170'], 'value': 'is'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'has_shared'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'shared'},{'id': '170', 'type': 'False', 'children': []},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'continue_statement', 'children': []},{'id': '173', 'type': 'if_statement', 'children': ['174', '183']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '182'], 'value': 'is'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'has_argument'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '182', 'type': 'False', 'children': []},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'continue_statement', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '191', '242']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '191', 'type': 'block', 'children': ['192', '205', '215', '231']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '195', 'type': 'list', 'children': ['196'], 'value': "[val.pop('lflag', '--%s' % key)]"},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'lflag'"},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '%'},{'id': '203', 'type': 'string', 'children': [], 'value': "'--%s'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'short'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': "'flag'"},{'id': '214', 'type': 'None', 'children': []},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '218', 'type': 'call', 'children': ['219', '228']},{'id': '219', 'type': 'attribute', 'children': ['220', '227']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'string', 'children': [], 'value': "'dest'"},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230']},{'id': '229', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '230', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '231', 'type': 'if_statement', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'short'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'short'},{'id': '242', 'type': 'else_clause', 'children': ['243']},{'id': '243', 'type': 'block', 'children': ['244', '251', '260']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '247', 'type': 'list', 'children': ['248'], 'value': "['--%s' % key]"},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '%'},{'id': '249', 'type': 'string', 'children': [], 'value': "'--%s'"},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '269', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '277']},{'id': '272', 'type': 'attribute', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '275', 'type': 'identifier', 'children': [], 'value': '__named__'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'tuple', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'arguments'}
def get_functarguments(func): argspec = inspect.getargspec(func) if argspec.defaults is not None: args = argspec.args[:-len(argspec.defaults)] kwargs = dict( zip(argspec.args[-len(argspec.defaults):], argspec.defaults)) else: args = argspec.args kwargs = {} if args and args[0] == 'self': args.pop(0) func.__named__ = [] arguments = [] shared = get_shared(func) for arg in args: if has_shared(arg, shared) is not False: continue if has_argument(arg, func.__cls__) is not False: continue arguments.append(([arg], {}, )) func.__named__.append(arg) for key, val in kwargs.items(): if has_shared(key, shared) is not False: continue if has_argument(key, func.__cls__) is not False: continue if isinstance(val, dict): flags = [val.pop('lflag', '--%s' % key)] short = val.pop('flag', None) dest = val.get('dest', key).replace('-', '_') if short: flags.insert(0, short) else: flags = ['--%s' % key] val = dict(default=val) dest = key.replace('-', '_') func.__named__.append(dest) arguments.append((flags, val, )) return arguments
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'family_file'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'family_type'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '9', 'type': 'block', 'children': ['10', '32', '55', '67', '79', '91', '115', '139', '146', '193', '205', '212', '224', '245', '266', '273', '280']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '24'], 'value': 'or'},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '16'], 'value': 'or'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'root'},{'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': 'ctx'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'root'"},{'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': 'expanduser'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"~/.puzzle"'},{'id': '32', 'type': 'if_statement', 'children': ['33', '41']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '41', 'type': 'block', 'children': ['42', '49']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '"\'root\' can\'t be a file"'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '54', 'type': 'argument_list', 'children': []},{'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': 'logger'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': '"Root directory is: {}"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'db_path'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '78', 'type': 'string', 'children': [], 'value': "'puzzle_db.sqlite3'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"db path is: {}"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'db_path'},{'id': '91', 'type': 'if_statement', 'children': ['92', '101']},{'id': '92', 'type': 'not_operator', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'db_path'},{'id': '101', 'type': 'block', 'children': ['102', '109']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': '"database not initialized, run \'puzzle init\'"'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '125']},{'id': '116', 'type': 'not_operator', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '125', 'type': 'block', 'children': ['126', '133']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': '"Variant source has to be a file"'},{'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': 'ctx'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'get_file_type'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150', '164']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '=='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '149', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '150', 'type': 'block', 'children': ['151', '158']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': '"Unknown file type"'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'elif_clause', 'children': ['165', '168']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '=='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '167', 'type': 'string', 'children': [], 'value': "'gemini'"},{'id': '168', 'type': 'block', 'children': ['169', '176']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': '"Initialzing GEMINI plugin"'},{'id': '176', 'type': 'if_statement', 'children': ['177', '179']},{'id': '177', 'type': 'not_operator', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'GEMINI'},{'id': '179', 'type': 'block', 'children': ['180', '187']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': '"Need to have gemini installed to use gemini plugin"'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'Set puzzle backend to {0}'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'get_variant_type'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'Set variant type to {0}'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'get_cases'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233', '236', '239', '242']},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'case_lines'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'family_file'},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'case_type'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'family_type'},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'variant_mode'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '245', 'type': 'if_statement', 'children': ['246', '252']},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '251'], 'value': '=='},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '251', 'type': 'integer', 'children': [], 'value': '0'},{'id': '252', 'type': 'block', 'children': ['253', '260']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'string', 'children': [], 'value': '"No cases found"'},{'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': 'ctx'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'abort'},{'id': '265', 'type': 'argument_list', 'children': []},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': '"Initializing sqlite plugin"'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'SqlStore'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'db_path'},{'id': '280', 'type': 'for_statement', 'children': ['281', '282', '283']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'cases'},{'id': '283', 'type': 'block', 'children': ['284', '311', '325']},{'id': '284', 'type': 'if_statement', 'children': ['285', '295']},{'id': '285', 'type': 'comparison_operator', 'children': ['286', '294'], 'value': 'is'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '294', 'type': 'None', 'children': []},{'id': '295', 'type': 'block', 'children': ['296', '310']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'string', 'children': [], 'value': '"{} already exists in the database"'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '310', 'type': 'continue_statement', 'children': []},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'string', 'children': [], 'value': '"adding case: {} to puzzle db"'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'add_case'},{'id': '330', 'type': 'argument_list', 'children': ['331', '332', '335']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'mode'}
def load(ctx, variant_source, family_file, family_type, root): root = root or ctx.obj.get('root') or os.path.expanduser("~/.puzzle") if os.path.isfile(root): logger.error("'root' can't be a file") ctx.abort() logger.info("Root directory is: {}".format(root)) db_path = os.path.join(root, 'puzzle_db.sqlite3') logger.info("db path is: {}".format(db_path)) if not os.path.exists(db_path): logger.warn("database not initialized, run 'puzzle init'") ctx.abort() if not os.path.isfile(variant_source): logger.error("Variant source has to be a file") ctx.abort() mode = get_file_type(variant_source) if mode == 'unknown': logger.error("Unknown file type") ctx.abort() elif mode == 'gemini': logger.debug("Initialzing GEMINI plugin") if not GEMINI: logger.error("Need to have gemini installed to use gemini plugin") ctx.abort() logger.debug('Set puzzle backend to {0}'.format(mode)) variant_type = get_variant_type(variant_source) logger.debug('Set variant type to {0}'.format(variant_type)) cases = get_cases( variant_source=variant_source, case_lines=family_file, case_type=family_type, variant_type=variant_type, variant_mode=mode ) if len(cases) == 0: logger.warning("No cases found") ctx.abort() logger.info("Initializing sqlite plugin") store = SqlStore(db_path) for case_obj in cases: if store.case(case_obj.case_id) is not None: logger.warn("{} already exists in the database" .format(case_obj.case_id)) continue logger.debug("adding case: {} to puzzle db".format(case_obj.case_id)) store.add_case(case_obj, vtype=variant_type, mode=mode)