sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'goto'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'goto_threshold'}; {'id': '8', 'type': 'float', 'children': [], 'value': '0.35'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'goto_mu'}, {'id': '11', 'type': 'float', 'children': [], 'value': '0.2'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'goto_sigma'}; {'id': '14', 'type': 'float', 'children': [], 'value': '0.2'}, {'id': '15', 'type': 'block', 'children': ['16', '22', '37', '50', '63', '67', '213', '229', '339', '374']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '34']}, {'id': '23', 'type': 'boolean_operator', 'children': ['24', '29'], 'value': 'or'}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '=='}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'float', 'children': [], 'value': '0.'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'beat_error'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'paired'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'subscript', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '80']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '79'], 'value': '-'}; {'id': '74', 'type': 'subscript', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'block', 'children': ['81', '96', '104', '119', '127', '143']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'previous_interval'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '*'}, {'id': '85', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '86', 'type': 'parenthesized_expression', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '91'], 'value': '-'}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '-'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'window_min'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '103'], 'value': '-'}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'previous_interval'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'next_interval'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '*'}; {'id': '108', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '109', 'type': 'parenthesized_expression', 'children': ['110']}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '116'], 'value': '-'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'window_max'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '+'}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'next_interval'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'beats_in_window'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'logical_and'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '139']}, {'id': '135', 'type': 'parenthesized_expression', 'children': ['136']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '>='}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'window_min'}, {'id': '139', 'type': 'parenthesized_expression', 'children': ['140']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '<'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'window_max'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '159', '172']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '152'], 'value': 'or'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '151'], 'value': '=='}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'beats_in_window'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': '>'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'beats_in_window'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'block', 'children': ['160', '166']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'paired'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '171']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'beat_error'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'else_clause', 'children': ['173']}, {'id': '173', 'type': 'block', 'children': ['174', '180', '190']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'paired'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '-'}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'estimated_beats'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'beats_in_window'}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '194', '203']}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '<'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'beat_error'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '/'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'previous_interval'}, {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'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': 'beat_error'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '/'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'next_interval'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'comparison_operator', 'children': ['222', '228'], 'value': '>'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'beat_error'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'goto_threshold'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '237', '260']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '236'], 'value': '<'}, {'id': '231', 'type': 'subscript', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '235', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '237', 'type': 'block', 'children': ['238', '256']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'track'}, {'id': '241', 'type': 'subscript', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'beat_error'}, {'id': '243', 'type': 'slice', 'children': ['244', '249', '250']}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '248'], 'value': '+'}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}, {'id': '247', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '248', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '249', 'type': 'colon', 'children': []}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '255'], 'value': '-'}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}, {'id': '253', 'type': 'unary_operator', 'children': ['254'], 'value': '-'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '255', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}, {'id': '261', 'type': 'block', 'children': ['262', '276', '294']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'track_len'}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'track_start'}, {'id': '279', 'type': 'subscript', 'children': ['280', '293']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'comparison_operator', 'children': ['286', '292'], 'value': '=='}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'track_len'}, {'id': '293', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '309']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '299'], 'value': '>'}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '-'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'track_len'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '301'], 'value': '*'}; {'id': '300', 'type': 'float', 'children': [], 'value': '.25'}, {'id': '301', 'type': 'parenthesized_expression', 'children': ['302']}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '308'], 'value': '-'}, {'id': '303', 'type': 'subscript', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'reference_beats'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '309', 'type': 'block', 'children': ['310', '314', '320', '328']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'assignment', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'start_beat'}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'track_start'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'end_beat'}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'incorrect_beats'}, {'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '+'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'track_start'}, {'id': '327', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'track'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'beat_error'}, {'id': '333', 'type': 'slice', 'children': ['334', '335', '336']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'start_beat'}, {'id': '335', 'type': 'colon', 'children': []}; {'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '+'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'end_beat'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '339', 'type': 'if_statement', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'}, {'id': '341', 'type': 'block', 'children': ['342']}; {'id': '342', 'type': 'if_statement', 'children': ['343', '369']}, {'id': '343', 'type': 'boolean_operator', 'children': ['344', '357', '358'], 'value': 'and'}; {'id': '344', 'type': 'comparison_operator', 'children': ['345', '356'], 'value': '<'}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'track'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'goto_mu'}, {'id': '357', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '358', 'type': 'comparison_operator', 'children': ['359', '368'], 'value': '<'}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'std'}, {'id': '363', 'type': 'argument_list', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'track'}, {'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'ddof'}, {'id': '367', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'goto_sigma'}, {'id': '369', 'type': 'block', 'children': ['370']}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}, {'id': '371', 'type': 'assignment', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'}, {'id': '373', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '374', 'type': 'return_statement', 'children': ['375']}, {'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '*'}; {'id': '376', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '377', 'type': 'parenthesized_expression', 'children': ['378']}; {'id': '378', 'type': 'comparison_operator', 'children': ['379', '380'], 'value': '=='}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'goto_criteria'} | def goto(reference_beats,
estimated_beats,
goto_threshold=0.35,
goto_mu=0.2,
goto_sigma=0.2):
validate(reference_beats, estimated_beats)
if estimated_beats.size == 0 or reference_beats.size == 0:
return 0.
beat_error = np.ones(reference_beats.shape[0])
paired = np.zeros(reference_beats.shape[0])
goto_criteria = 0
for n in range(1, reference_beats.shape[0]-1):
previous_interval = 0.5*(reference_beats[n] - reference_beats[n-1])
window_min = reference_beats[n] - previous_interval
next_interval = 0.5*(reference_beats[n+1] - reference_beats[n])
window_max = reference_beats[n] + next_interval
beats_in_window = np.logical_and((estimated_beats >= window_min),
(estimated_beats < window_max))
if beats_in_window.sum() == 0 or beats_in_window.sum() > 1:
paired[n] = 0
beat_error[n] = 1
else:
paired[n] = 1
offset = estimated_beats[beats_in_window] - reference_beats[n]
if offset < 0:
beat_error[n] = offset/previous_interval
else:
beat_error[n] = offset/next_interval
incorrect_beats = np.flatnonzero(np.abs(beat_error) > goto_threshold)
if incorrect_beats.shape[0] < 3:
track = beat_error[incorrect_beats[0] + 1:incorrect_beats[-1] - 1]
goto_criteria = 1
else:
track_len = np.max(np.diff(incorrect_beats))
track_start = np.flatnonzero(np.diff(incorrect_beats) == track_len)[0]
if track_len - 1 > .25*(reference_beats.shape[0] - 2):
goto_criteria = 1
start_beat = incorrect_beats[track_start]
end_beat = incorrect_beats[track_start + 1]
track = beat_error[start_beat:end_beat + 1]
if goto_criteria:
if np.mean(np.abs(track)) < goto_mu \
and np.std(track, ddof=1) < goto_sigma:
goto_criteria = 3
return 1.0*(goto_criteria == 3) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_labeled_intervals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '24', '30']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Sort intervals, and optionally, their corresponding labels\n according to start time.\n Parameters\n ----------\n intervals : np.ndarray, shape=(n, 2)\n The input intervals\n labels : list, optional\n Labels for each interval\n Returns\n -------\n intervals_sorted or (intervals_sorted, labels_sorted)\n Labels are only returned if provided as input\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21', '23']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '21', 'type': 'slice', 'children': ['22']}; {'id': '22', 'type': 'colon', 'children': []}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'intervals_sorted'}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34', '37']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'intervals_sorted'}, {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'expression_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'intervals_sorted'}; {'id': '42', 'type': 'list_comprehension', 'children': ['43', '46']}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_'} | def sort_labeled_intervals(intervals, labels=None):
'''Sort intervals, and optionally, their corresponding labels
according to start time.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
The input intervals
labels : list, optional
Labels for each interval
Returns
-------
intervals_sorted or (intervals_sorted, labels_sorted)
Labels are only returned if provided as input
'''
idx = np.argsort(intervals[:, 0])
intervals_sorted = intervals[idx]
if labels is None:
return intervals_sorted
else:
return intervals_sorted, [labels[_] for _ in idx] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bss_eval_sources'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '27', '44', '50', '89', '97']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': '=='}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ndim'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'estimated_sources'}; {'id': '20', 'type': 'subscript', 'children': ['21', '22', '25']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'newaxis'}, {'id': '25', 'type': 'slice', 'children': ['26']}; {'id': '26', 'type': 'colon', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '33']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ndim'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'newaxis'}; {'id': '42', 'type': 'slice', 'children': ['43']}, {'id': '43', 'type': 'colon', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '62']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '57'], 'value': 'or'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '=='}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'expression_list', 'children': ['65', '71', '77', '83']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99', '283']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}, {'id': '99', 'type': 'block', 'children': ['100', '111', '122', '133', '187', '205', '217', '226', '249', '260', '266']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'tuple', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'tuple', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'tuple', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '133', 'type': 'for_statement', 'children': ['134', '135', '139']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'jest'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'for_statement', 'children': ['141', '142', '146']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'jtrue'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '146', 'type': 'block', 'children': ['147', '164']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '154', '155']}, {'id': '149', 'type': 'pattern_list', 'children': ['150', '151', '152', '153']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 's_true'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'e_spat'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'e_interf'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'e_artif'}; {'id': '154', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_bss_decomp_mtifilt'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159', '162', '163']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'jest'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'jtrue'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '512'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '179', '180']}; {'id': '166', 'type': 'pattern_list', 'children': ['167', '171', '175']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169', '170']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'jest'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'jtrue'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173', '174']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'jest'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'jtrue'}, {'id': '175', 'type': 'subscript', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'jest'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'jtrue'}, {'id': '179', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_bss_source_crit'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184', '185', '186']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 's_true'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'e_spat'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'e_interf'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'e_artif'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'permutations'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'mean_sir'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'dum'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '226', 'type': 'for_statement', 'children': ['227', '230', '234']}, {'id': '227', 'type': 'tuple_pattern', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '234', 'type': 'block', 'children': ['235']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'mean_sir'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': 'mean'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'subscript', 'children': ['246', '247', '248']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'dum'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'popt'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'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': 'argmax'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'mean_sir'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '263', 'type': 'tuple', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'popt'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'dum'}; {'id': '266', 'type': 'return_statement', 'children': ['267']}, {'id': '267', 'type': 'tuple', 'children': ['268', '271', '274', '277']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '274', 'type': 'subscript', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'sar'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'popt'}, {'id': '283', 'type': 'else_clause', 'children': ['284']}; {'id': '284', 'type': 'block', 'children': ['285', '294', '303', '312', '356', '365']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'sar'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '312', 'type': 'for_statement', 'children': ['313', '314', '318']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '318', 'type': 'block', 'children': ['319', '336']}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'assignment', 'children': ['321', '326', '327']}, {'id': '321', 'type': 'pattern_list', 'children': ['322', '323', '324', '325']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 's_true'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'e_spat'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'e_interf'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'e_artif'}; {'id': '326', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': '_bss_decomp_mtifilt'}, {'id': '329', 'type': 'argument_list', 'children': ['330', '331', '334', '335']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '335', 'type': 'integer', 'children': [], 'value': '512'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '348', '349']}; {'id': '338', 'type': 'pattern_list', 'children': ['339', '342', '345']}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '342', 'type': 'subscript', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '345', 'type': 'subscript', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '348', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '349', 'type': 'call', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': '_bss_source_crit'}, {'id': '351', 'type': 'argument_list', 'children': ['352', '353', '354', '355']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 's_true'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'e_spat'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'e_interf'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'e_artif'}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'assignment', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'popt'}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '365', 'type': 'return_statement', 'children': ['366']}; {'id': '366', 'type': 'tuple', 'children': ['367', '368', '369', '370']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'sar'} | def bss_eval_sources(reference_sources, estimated_sources,
compute_permutation=True):
if estimated_sources.ndim == 1:
estimated_sources = estimated_sources[np.newaxis, :]
if reference_sources.ndim == 1:
reference_sources = reference_sources[np.newaxis, :]
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = estimated_sources.shape[0]
if compute_permutation:
sdr = np.empty((nsrc, nsrc))
sir = np.empty((nsrc, nsrc))
sar = np.empty((nsrc, nsrc))
for jest in range(nsrc):
for jtrue in range(nsrc):
s_true, e_spat, e_interf, e_artif = \
_bss_decomp_mtifilt(reference_sources,
estimated_sources[jest],
jtrue, 512)
sdr[jest, jtrue], sir[jest, jtrue], sar[jest, jtrue] = \
_bss_source_crit(s_true, e_spat, e_interf, e_artif)
perms = list(itertools.permutations(list(range(nsrc))))
mean_sir = np.empty(len(perms))
dum = np.arange(nsrc)
for (i, perm) in enumerate(perms):
mean_sir[i] = np.mean(sir[perm, dum])
popt = perms[np.argmax(mean_sir)]
idx = (popt, dum)
return (sdr[idx], sir[idx], sar[idx], np.asarray(popt))
else:
sdr = np.empty(nsrc)
sir = np.empty(nsrc)
sar = np.empty(nsrc)
for j in range(nsrc):
s_true, e_spat, e_interf, e_artif = \
_bss_decomp_mtifilt(reference_sources,
estimated_sources[j],
j, 512)
sdr[j], sir[j], sar[j] = \
_bss_source_crit(s_true, e_spat, e_interf, e_artif)
popt = np.arange(nsrc)
return (sdr, sir, sar, popt) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bss_eval_sources_framewise'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '8', 'type': 'binary_operator', 'children': ['9', '10'], 'value': '*'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '44100'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '*'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '15'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '44100'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '37', '54', '60', '99', '107', '130', '157', '168', '179', '190', '201', '311']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '=='}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ndim'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'newaxis'}, {'id': '35', 'type': 'slice', 'children': ['36']}; {'id': '36', 'type': 'colon', 'children': []}, {'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': 'reference_sources'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ndim'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'reference_sources'}, {'id': '47', 'type': 'subscript', 'children': ['48', '49', '52']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'newaxis'}; {'id': '52', 'type': 'slice', 'children': ['53']}, {'id': '53', 'type': 'colon', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '72']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '67'], 'value': 'or'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '=='}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '71'], 'value': '=='}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'expression_list', 'children': ['75', '81', '87', '93']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '102', 'type': 'subscript', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '129'], 'value': '/'}, {'id': '119', 'type': 'parenthesized_expression', 'children': ['120']}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '128'], 'value': '+'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '127'], 'value': '-'}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'hop'}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '<'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '134', 'type': 'block', 'children': ['135', '144']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'bss_eval_sources'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '144', 'type': 'return_statement', 'children': ['145']}, {'id': '145', 'type': 'list_comprehension', 'children': ['146', '154']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'expand_dims'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '152', 'type': 'unary_operator', 'children': ['153'], 'value': '-'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'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': 'empty'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'tuple', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'tuple', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'sar'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'tuple', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'perm'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'tuple', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '201', 'type': 'for_statement', 'children': ['202', '203', '207']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '207', 'type': 'block', 'children': ['208', '222', '230', '238']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'win_slice'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'slice'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '217']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '*'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '217', 'type': 'binary_operator', 'children': ['218', '221'], 'value': '+'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '*'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}, {'id': '225', 'type': 'subscript', 'children': ['226', '227', '229']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '227', 'type': 'slice', 'children': ['228']}; {'id': '228', 'type': 'colon', 'children': []}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'win_slice'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'est_slice'}, {'id': '233', 'type': 'subscript', 'children': ['234', '235', '237']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '235', 'type': 'slice', 'children': ['236']}; {'id': '236', 'type': 'colon', 'children': []}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'win_slice'}; {'id': '238', 'type': 'if_statement', 'children': ['239', '251', '281']}, {'id': '239', 'type': 'parenthesized_expression', 'children': ['240']}; {'id': '240', 'type': 'boolean_operator', 'children': ['241', '246'], 'value': 'and'}, {'id': '241', 'type': 'not_operator', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': '_any_source_silent'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}; {'id': '246', 'type': 'not_operator', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '_any_source_silent'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'est_slice'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '275']}; {'id': '254', 'type': 'pattern_list', 'children': ['255', '260', '265', '270']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257', '259']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '257', 'type': 'slice', 'children': ['258']}; {'id': '258', 'type': 'colon', 'children': []}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262', '264']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '262', 'type': 'slice', 'children': ['263']}, {'id': '263', 'type': 'colon', 'children': []}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '265', 'type': 'subscript', 'children': ['266', '267', '269']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '267', 'type': 'slice', 'children': ['268']}; {'id': '268', 'type': 'colon', 'children': []}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272', '274']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '272', 'type': 'slice', 'children': ['273']}, {'id': '273', 'type': 'colon', 'children': []}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'bss_eval_sources'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '279', '280']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'est_slice'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}, {'id': '281', 'type': 'else_clause', 'children': ['282']}; {'id': '282', 'type': 'block', 'children': ['283']}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '290']}, {'id': '285', 'type': 'subscript', 'children': ['286', '287', '289']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '287', 'type': 'slice', 'children': ['288']}; {'id': '288', 'type': 'colon', 'children': []}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '290', 'type': 'assignment', 'children': ['291', '296']}, {'id': '291', 'type': 'subscript', 'children': ['292', '293', '295']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '293', 'type': 'slice', 'children': ['294']}; {'id': '294', 'type': 'colon', 'children': []}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '296', 'type': 'assignment', 'children': ['297', '302']}, {'id': '297', 'type': 'subscript', 'children': ['298', '299', '301']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '299', 'type': 'slice', 'children': ['300']}; {'id': '300', 'type': 'colon', 'children': []}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '302', 'type': 'assignment', 'children': ['303', '308']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305', '307']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'perm'}, {'id': '305', 'type': 'slice', 'children': ['306']}; {'id': '306', 'type': 'colon', 'children': []}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'nan'}, {'id': '311', 'type': 'return_statement', 'children': ['312']}; {'id': '312', 'type': 'expression_list', 'children': ['313', '314', '315', '316']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'sar'} | def bss_eval_sources_framewise(reference_sources, estimated_sources,
window=30*44100, hop=15*44100,
compute_permutation=False):
if estimated_sources.ndim == 1:
estimated_sources = estimated_sources[np.newaxis, :]
if reference_sources.ndim == 1:
reference_sources = reference_sources[np.newaxis, :]
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = reference_sources.shape[0]
nwin = int(
np.floor((reference_sources.shape[1] - window + hop) / hop)
)
if nwin < 2:
result = bss_eval_sources(reference_sources,
estimated_sources,
compute_permutation)
return [np.expand_dims(score, -1) for score in result]
sdr = np.empty((nsrc, nwin))
sir = np.empty((nsrc, nwin))
sar = np.empty((nsrc, nwin))
perm = np.empty((nsrc, nwin))
for k in range(nwin):
win_slice = slice(k * hop, k * hop + window)
ref_slice = reference_sources[:, win_slice]
est_slice = estimated_sources[:, win_slice]
if (not _any_source_silent(ref_slice) and
not _any_source_silent(est_slice)):
sdr[:, k], sir[:, k], sar[:, k], perm[:, k] = bss_eval_sources(
ref_slice, est_slice, compute_permutation
)
else:
sdr[:, k] = sir[:, k] = sar[:, k] = perm[:, k] = np.nan
return sdr, sir, sar, perm |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bss_eval_images_framewise'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '8', 'type': 'binary_operator', 'children': ['9', '10'], 'value': '*'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '44100'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '*'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '15'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '44100'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '29', '38', '44', '83', '91', '114', '141', '152', '163', '174', '185', '196', '316']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'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': 'atleast_3d'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'atleast_3d'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '56']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '51'], 'value': 'or'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '=='}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'expression_list', 'children': ['59', '65', '71', '77']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '113'], 'value': '/'}, {'id': '103', 'type': 'parenthesized_expression', 'children': ['104']}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '112'], 'value': '+'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '111'], 'value': '-'}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'hop'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'hop'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '<'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '118', 'type': 'block', 'children': ['119', '128']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'bss_eval_images'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '128', 'type': 'return_statement', 'children': ['129']}, {'id': '129', 'type': 'list_comprehension', 'children': ['130', '138']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'expand_dims'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'for_in_clause', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'tuple', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'isr'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'tuple', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'tuple', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'tuple', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'nsrc'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'nwin'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'tuple', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'nsrc'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '196', 'type': 'for_statement', 'children': ['197', '198', '202']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'nwin'}; {'id': '202', 'type': 'block', 'children': ['203', '217', '227', '237']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'win_slice'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'slice'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212']}, {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '*'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'hop'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '216'], 'value': '+'}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '*'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'hop'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222', '224', '225']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'reference_sources'}; {'id': '222', 'type': 'slice', 'children': ['223']}, {'id': '223', 'type': 'colon', 'children': []}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'win_slice'}, {'id': '225', 'type': 'slice', 'children': ['226']}; {'id': '226', 'type': 'colon', 'children': []}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'est_slice'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232', '234', '235']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'estimated_sources'}; {'id': '232', 'type': 'slice', 'children': ['233']}, {'id': '233', 'type': 'colon', 'children': []}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'win_slice'}, {'id': '235', 'type': 'slice', 'children': ['236']}; {'id': '236', 'type': 'colon', 'children': []}, {'id': '237', 'type': 'if_statement', 'children': ['238', '250', '286']}; {'id': '238', 'type': 'parenthesized_expression', 'children': ['239']}, {'id': '239', 'type': 'boolean_operator', 'children': ['240', '245'], 'value': 'and'}; {'id': '240', 'type': 'not_operator', 'children': ['241']}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': '_any_source_silent'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}, {'id': '245', 'type': 'not_operator', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '_any_source_silent'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'est_slice'}; {'id': '250', 'type': 'block', 'children': ['251']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '279', '280']}, {'id': '253', 'type': 'pattern_list', 'children': ['254', '259', '264', '269', '274']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256', '258']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '256', 'type': 'slice', 'children': ['257']}, {'id': '257', 'type': 'colon', 'children': []}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '259', 'type': 'subscript', 'children': ['260', '261', '263']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'isr'}, {'id': '261', 'type': 'slice', 'children': ['262']}; {'id': '262', 'type': 'colon', 'children': []}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '264', 'type': 'subscript', 'children': ['265', '266', '268']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '266', 'type': 'slice', 'children': ['267']}, {'id': '267', 'type': 'colon', 'children': []}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '269', 'type': 'subscript', 'children': ['270', '271', '273']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'sar'}, {'id': '271', 'type': 'slice', 'children': ['272']}; {'id': '272', 'type': 'colon', 'children': []}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '274', 'type': 'subscript', 'children': ['275', '276', '278']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '276', 'type': 'slice', 'children': ['277']}, {'id': '277', 'type': 'colon', 'children': []}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '279', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'bss_eval_images'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284', '285']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'ref_slice'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'est_slice'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'compute_permutation'}; {'id': '286', 'type': 'else_clause', 'children': ['287']}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '295']}; {'id': '290', 'type': 'subscript', 'children': ['291', '292', '294']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'sdr'}; {'id': '292', 'type': 'slice', 'children': ['293']}, {'id': '293', 'type': 'colon', 'children': []}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '295', 'type': 'assignment', 'children': ['296', '301']}; {'id': '296', 'type': 'subscript', 'children': ['297', '298', '300']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'sir'}; {'id': '298', 'type': 'slice', 'children': ['299']}, {'id': '299', 'type': 'colon', 'children': []}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '301', 'type': 'assignment', 'children': ['302', '307']}; {'id': '302', 'type': 'subscript', 'children': ['303', '304', '306']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'sar'}; {'id': '304', 'type': 'slice', 'children': ['305']}, {'id': '305', 'type': 'colon', 'children': []}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '307', 'type': 'assignment', 'children': ['308', '313']}; {'id': '308', 'type': 'subscript', 'children': ['309', '310', '312']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'perm'}; {'id': '310', 'type': 'slice', 'children': ['311']}, {'id': '311', 'type': 'colon', 'children': []}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'nan'}; {'id': '316', 'type': 'return_statement', 'children': ['317']}, {'id': '317', 'type': 'expression_list', 'children': ['318', '319', '320', '321', '322']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'sdr'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'isr'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'sir'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'sar'} | def bss_eval_images_framewise(reference_sources, estimated_sources,
window=30*44100, hop=15*44100,
compute_permutation=False):
estimated_sources = np.atleast_3d(estimated_sources)
reference_sources = np.atleast_3d(reference_sources)
validate(reference_sources, estimated_sources)
if reference_sources.size == 0 or estimated_sources.size == 0:
return np.array([]), np.array([]), np.array([]), np.array([])
nsrc = reference_sources.shape[0]
nwin = int(
np.floor((reference_sources.shape[1] - window + hop) / hop)
)
if nwin < 2:
result = bss_eval_images(reference_sources,
estimated_sources,
compute_permutation)
return [np.expand_dims(score, -1) for score in result]
sdr = np.empty((nsrc, nwin))
isr = np.empty((nsrc, nwin))
sir = np.empty((nsrc, nwin))
sar = np.empty((nsrc, nwin))
perm = np.empty((nsrc, nwin))
for k in range(nwin):
win_slice = slice(k * hop, k * hop + window)
ref_slice = reference_sources[:, win_slice, :]
est_slice = estimated_sources[:, win_slice, :]
if (not _any_source_silent(ref_slice) and
not _any_source_silent(est_slice)):
sdr[:, k], isr[:, k], sir[:, k], sar[:, k], perm[:, k] = \
bss_eval_images(
ref_slice, est_slice, compute_permutation
)
else:
sdr[:, k] = sir[:, k] = sar[:, k] = perm[:, k] = np.nan
return sdr, isr, sir, sar, perm |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'time_frequency'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'gram'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sin'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'n_dec'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '19', 'type': 'block', 'children': ['20', '36', '54', '68', '76', '84', '179', '193', '203', '212', '229', '347', '360', '378']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '=='}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ndim'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'boundaries_to_intervals'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '53'], 'value': '*'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50', '52']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'pattern_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'adjust_intervals'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 't_max'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'n_times'}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'gram'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '81', 'type': 'slice', 'children': ['82', '83']}; {'id': '82', 'type': 'colon', 'children': []}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'n_times'}; {'id': '84', 'type': 'function_definition', 'children': ['85', '86', '88']}, {'id': '85', 'type': 'function_name', 'children': [], 'value': '_fast_synthesize'}; {'id': '86', 'type': 'parameters', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'frequency'}; {'id': '88', 'type': 'block', 'children': ['89', '99', '110', '132', '153', '175']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'frequency'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'frequency'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'n_dec'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'n_samples'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '109'], 'value': '*'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '**'}, {'id': '107', 'type': 'float', 'children': [], 'value': '10.0'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'n_dec'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'short_signal'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'function'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '131'], 'value': '/'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '130'], 'value': '*'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '124'], 'value': '*'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '*'}; {'id': '120', 'type': 'float', 'children': [], 'value': '2.0'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'n_samples'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'n_repeats'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ceil'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '/'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'short_signal'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'long_signal'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'as_strided'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160', '168']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'short_signal'}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '162', 'type': 'tuple', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'n_repeats'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'short_signal'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'strides'}; {'id': '170', 'type': 'tuple', 'children': ['171', '172']}, {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'short_signal'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'itemsize'}, {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'long_signal'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'flat'}, {'id': '179', 'type': 'function_definition', 'children': ['180', '181', '183']}; {'id': '180', 'type': 'function_name', 'children': [], 'value': '_const_interpolator'}, {'id': '181', 'type': 'parameters', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '183', 'type': 'block', 'children': ['184', '191']}; {'id': '184', 'type': 'function_definition', 'children': ['185', '186', '188']}, {'id': '185', 'type': 'function_name', 'children': [], 'value': '__interpolator'}; {'id': '186', 'type': 'parameters', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '191', 'type': 'return_statement', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '__interpolator'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'gram'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'gram'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'time_centers'}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '225'], 'value': '*'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'fs'}, {'id': '229', 'type': 'for_statement', 'children': ['230', '233', '237']}; {'id': '230', 'type': 'pattern_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '237', 'type': 'block', 'children': ['238', '245', '286']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'wave'}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': '_fast_synthesize'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '245', 'type': 'if_statement', 'children': ['246', '252', '274']}; {'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': 'time_centers'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'gram_interpolator'}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'interp1d'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '260', '265', '268', '271']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'time_centers'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262', '263']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'gram'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '263', 'type': 'slice', 'children': ['264']}; {'id': '264', 'type': 'colon', 'children': []}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '267', 'type': 'string', 'children': [], 'value': "'linear'"}; {'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'bounds_error'}; {'id': '270', 'type': 'False', 'children': []}, {'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'fill_value'}, {'id': '273', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '274', 'type': 'else_clause', 'children': ['275']}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'gram_interpolator'}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': '_const_interpolator'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'subscript', 'children': ['283', '284', '285']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'gram'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '285', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '286', 'type': 'for_statement', 'children': ['287', '292', '304']}, {'id': '287', 'type': 'pattern_list', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '289', 'type': 'tuple_pattern', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '302']}; {'id': '296', 'type': 'attribute', 'children': ['297', '301']}, {'id': '297', 'type': 'parenthesized_expression', 'children': ['298']}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '*'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'fs'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '304', 'type': 'block', 'children': ['305', '321']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '310']}, {'id': '307', 'type': 'pattern_list', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '310', 'type': 'expression_list', 'children': ['311', '316']}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'call', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'augmented_assignment', 'children': ['323', '329'], 'value': '+='}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '325', 'type': 'slice', 'children': ['326', '327', '328']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '327', 'type': 'colon', 'children': []}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '329', 'type': 'parenthesized_expression', 'children': ['330']}; {'id': '330', 'type': 'binary_operator', 'children': ['331', '337'], 'value': '*'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'wave'}, {'id': '333', 'type': 'slice', 'children': ['334', '335', '336']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '335', 'type': 'colon', 'children': []}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '337', 'type': 'call', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'gram_interpolator'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '344', 'type': 'argument_list', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '350', 'type': 'call', 'children': ['351', '359']}, {'id': '351', 'type': 'attribute', 'children': ['352', '358']}; {'id': '352', 'type': 'call', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '359', 'type': 'argument_list', 'children': []}; {'id': '360', 'type': 'if_statement', 'children': ['361', '373']}, {'id': '361', 'type': 'comparison_operator', 'children': ['362', '363'], 'value': '>='}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '363', 'type': 'attribute', 'children': ['364', '372']}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'finfo'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'tiny'}, {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'augmented_assignment', 'children': ['376', '377'], 'value': '/='}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '378', 'type': 'return_statement', 'children': ['379']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'output'} | def time_frequency(gram, frequencies, times, fs, function=np.sin, length=None,
n_dec=1):
if times.ndim == 1:
times = util.boundaries_to_intervals(times)
if length is None:
length = int(times[-1, 1] * fs)
times, _ = util.adjust_intervals(times, t_max=length)
n_times = gram.shape[1]
times = times[:n_times]
def _fast_synthesize(frequency):
frequency = np.round(frequency, n_dec)
n_samples = int(10.0**n_dec * fs)
short_signal = function(2.0 * np.pi * np.arange(n_samples) *
frequency / fs)
n_repeats = int(np.ceil(length/float(short_signal.shape[0])))
long_signal = as_strided(short_signal,
shape=(n_repeats, len(short_signal)),
strides=(0, short_signal.itemsize))
return long_signal.flat
def _const_interpolator(value):
def __interpolator(x):
return value
return __interpolator
gram = np.maximum(gram, 0)
output = np.zeros(length)
time_centers = np.mean(times, axis=1) * float(fs)
for n, frequency in enumerate(frequencies):
wave = _fast_synthesize(frequency)
if len(time_centers) > 1:
gram_interpolator = interp1d(
time_centers, gram[n, :],
kind='linear', bounds_error=False,
fill_value=0.0)
else:
gram_interpolator = _const_interpolator(gram[n, 0])
for m, (start, end) in enumerate((times * fs).astype(int)):
start, end = max(start, 0), min(end, length)
output[start:end] += (
wave[start:end] * gram_interpolator(np.arange(start, end)))
norm = np.abs(output).max()
if norm >= np.finfo(output.dtype).tiny:
output /= norm
return output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_note_offsets'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'offset_ratio'}; {'id': '8', 'type': 'float', 'children': [], 'value': '0.2'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'offset_min_tolerance'}, {'id': '11', 'type': 'float', 'children': [], 'value': '0.05'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '33', '58', '70', '79', '91', '107', '116', '120', '150', '166']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '18', '25']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'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': 'cmp_func'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'less'}, {'id': '25', 'type': 'else_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cmp_func'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'less_equal'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'offset_distances'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'subtract'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'outer'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50', '52']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}; {'id': '50', 'type': 'slice', 'children': ['51']}, {'id': '51', 'type': 'colon', 'children': []}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55', '57']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}, {'id': '55', 'type': 'slice', 'children': ['56']}; {'id': '56', 'type': 'colon', 'children': []}, {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'offset_distances'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'around'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'offset_distances'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'decimals'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'N_DECIMALS'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ref_durations'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'intervals_to_durations'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'offset_tolerances'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '*'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'offset_ratio'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ref_durations'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'offset_min_tolerance'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'offset_hit_matrix'}; {'id': '94', 'type': 'parenthesized_expression', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'cmp_func'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'offset_distances'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'offset_tolerances'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '106']}; {'id': '104', 'type': 'unary_operator', 'children': ['105'], 'value': '-'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'offset_hit_matrix'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '119', 'type': 'dictionary', 'children': []}; {'id': '120', 'type': 'for_statement', 'children': ['121', '124', '129']}, {'id': '121', 'type': 'pattern_list', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ref_i'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'est_i'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'list_splat', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hits'}, {'id': '129', 'type': 'block', 'children': ['130', '141']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'est_i'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'est_i'}; {'id': '140', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '148']}, {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'est_i'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ref_i'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '165']}, {'id': '157', 'type': 'attribute', 'children': ['158', '164']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_bipartite_match'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '165', 'type': 'argument_list', 'children': []}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'matching'} | def match_note_offsets(ref_intervals, est_intervals, offset_ratio=0.2,
offset_min_tolerance=0.05, strict=False):
if strict:
cmp_func = np.less
else:
cmp_func = np.less_equal
offset_distances = np.abs(np.subtract.outer(ref_intervals[:, 1],
est_intervals[:, 1]))
offset_distances = np.around(offset_distances, decimals=N_DECIMALS)
ref_durations = util.intervals_to_durations(ref_intervals)
offset_tolerances = np.maximum(offset_ratio * ref_durations,
offset_min_tolerance)
offset_hit_matrix = (
cmp_func(offset_distances, offset_tolerances.reshape(-1, 1)))
hits = np.where(offset_hit_matrix)
G = {}
for ref_i, est_i in zip(*hits):
if est_i not in G:
G[est_i] = []
G[est_i].append(ref_i)
matching = sorted(util._bipartite_match(G).items())
return matching |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_note_onsets'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'onset_tolerance'}; {'id': '8', 'type': 'float', 'children': [], 'value': '0.05'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '30', '55', '67', '75', '84', '88', '118', '134']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '15', '22']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'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': 'cmp_func'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'less'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cmp_func'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'less_equal'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'onset_distances'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'subtract'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'outer'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '50']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47', '49']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}, {'id': '47', 'type': 'slice', 'children': ['48']}; {'id': '48', 'type': 'colon', 'children': []}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52', '54']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}; {'id': '52', 'type': 'slice', 'children': ['53']}, {'id': '53', 'type': 'colon', 'children': []}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'onset_distances'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'around'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'onset_distances'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'decimals'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'N_DECIMALS'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'onset_hit_matrix'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cmp_func'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'onset_distances'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'onset_tolerance'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'onset_hit_matrix'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '87', 'type': 'dictionary', 'children': []}; {'id': '88', 'type': 'for_statement', 'children': ['89', '92', '97']}, {'id': '89', 'type': 'pattern_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ref_i'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'est_i'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'list_splat', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'hits'}, {'id': '97', 'type': 'block', 'children': ['98', '109']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'not'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'est_i'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'est_i'}; {'id': '108', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '116']}, {'id': '111', 'type': 'attribute', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'est_i'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ref_i'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '133']}, {'id': '125', 'type': 'attribute', 'children': ['126', '132']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_bipartite_match'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'return_statement', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'matching'} | def match_note_onsets(ref_intervals, est_intervals, onset_tolerance=0.05,
strict=False):
if strict:
cmp_func = np.less
else:
cmp_func = np.less_equal
onset_distances = np.abs(np.subtract.outer(ref_intervals[:, 0],
est_intervals[:, 0]))
onset_distances = np.around(onset_distances, decimals=N_DECIMALS)
onset_hit_matrix = cmp_func(onset_distances, onset_tolerance)
hits = np.where(onset_hit_matrix)
G = {}
for ref_i, est_i in zip(*hits):
if est_i not in G:
G[est_i] = []
G[est_i].append(ref_i)
matching = sorted(util._bipartite_match(G).items())
return matching |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_time'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_freqs'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'est_time'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'est_freqs'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '43', '55', '70', '84', '96', '111', '128', '145', '165']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'validate_events'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ref_time'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'max_time'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'MAX_TIME'}, {'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': 'util'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'validate_events'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'est_time'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_time'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'MAX_TIME'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '=='}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ref_time'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Reference times are empty."'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '49']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '!='}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ref_time'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ndim'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'string', 'children': [], 'value': '"Reference times have invalid dimension"'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '62']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '=='}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ref_freqs'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"Reference frequencies are empty."'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '=='}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'est_time'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'size'}, {'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': 'warnings'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'string', 'children': [], 'value': '"Estimated times are empty."'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '90']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '!='}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'est_time'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ndim'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Estimated times have invalid dimension"'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '103']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '=='}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'est_freqs'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'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': 'warnings'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"Estimated frequencies are empty."'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '120']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': '!='}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'ref_time'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ref_freqs'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'concatenated_string', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'Reference times and frequencies have unequal '"}, {'id': '127', 'type': 'string', 'children': [], 'value': "'lengths.'"}; {'id': '128', 'type': 'if_statement', 'children': ['129', '137']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '!='}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'est_time'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'est_freqs'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'raise_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'concatenated_string', 'children': ['143', '144']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'Estimate times and frequencies have unequal '"}; {'id': '144', 'type': 'string', 'children': [], 'value': "'lengths.'"}, {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ref_freqs'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'validate_frequencies'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '159', '162']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'max_freq'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'MAX_FREQ'}, {'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'min_freq'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'MIN_FREQ'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'allow_negatives'}; {'id': '164', 'type': 'False', 'children': []}, {'id': '165', 'type': 'for_statement', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'est_freqs'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'validate_frequencies'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176', '179', '182']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'max_freq'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'MAX_FREQ'}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'min_freq'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'MIN_FREQ'}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'allow_negatives'} | def validate(ref_time, ref_freqs, est_time, est_freqs):
util.validate_events(ref_time, max_time=MAX_TIME)
util.validate_events(est_time, max_time=MAX_TIME)
if ref_time.size == 0:
warnings.warn("Reference times are empty.")
if ref_time.ndim != 1:
raise ValueError("Reference times have invalid dimension")
if len(ref_freqs) == 0:
warnings.warn("Reference frequencies are empty.")
if est_time.size == 0:
warnings.warn("Estimated times are empty.")
if est_time.ndim != 1:
raise ValueError("Estimated times have invalid dimension")
if len(est_freqs) == 0:
warnings.warn("Estimated frequencies are empty.")
if ref_time.size != len(ref_freqs):
raise ValueError('Reference times and frequencies have unequal '
'lengths.')
if est_time.size != len(est_freqs):
raise ValueError('Estimate times and frequencies have unequal '
'lengths.')
for freq in ref_freqs:
util.validate_frequencies(freq, max_freq=MAX_FREQ, min_freq=MIN_FREQ,
allow_negatives=False)
for freq in est_freqs:
util.validate_frequencies(freq, max_freq=MAX_FREQ, min_freq=MIN_FREQ,
allow_negatives=False) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'segments'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'block', 'children': ['24', '26', '37', '45', '53', '69', '78', '87', '98', '110', '125', '140', '148', '154', '222', '312', '322', '346']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'''Plot a segmentation as a set of disjoint rectangles.\n Parameters\n ----------\n intervals : np.ndarray, shape=(n, 2)\n segment intervals, in the format returned by\n :func:`mir_eval.io.load_intervals` or\n :func:`mir_eval.io.load_labeled_intervals`.\n labels : list, shape=(n,)\n reference segment labels, in the format returned by\n :func:`mir_eval.io.load_labeled_intervals`.\n base : number\n The vertical position of the base of the rectangles.\n By default, this will be the bottom of the plot.\n height : number\n The height of the rectangles.\n By default, this will be the top of the plot (minus ``base``).\n text : bool\n If true, each segment's label is displayed in its\n upper-left corner\n text_kw : dict\n If ``text == True``, the properties of the text\n object can be specified here.\n See ``matplotlib.pyplot.Text`` for valid parameters\n ax : matplotlib.pyplot.axes\n An axis handle on which to draw the segmentation.\n If none is provided, a new set of axes is created.\n kwargs\n Additional keyword arguments to pass to\n ``matplotlib.patches.Rectangle``.\n Returns\n -------\n ax : matplotlib.pyplot.axes._subplots.AxesSubplot\n A handle to the (possibly constructed) plot axes\n '''"}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'text_kw'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'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': 'text_kw'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'va'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'top'"}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'clip_on'"}; {'id': '52', 'type': 'True', 'children': []}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'bbox'"}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66']}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'boxstyle'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'round'"}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'facecolor'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'white'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'seg_def_style'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'linewidth'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'ax'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'new_axes'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '__get_axes'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_axes'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'set_ylim'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'list', 'children': ['108', '109'], 'value': '[0, 1]'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '118', 'type': 'subscript', 'children': ['119', '124']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_ylim'}, {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '133', 'type': 'subscript', 'children': ['134', '139']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'get_ylim'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'cycler'}, {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_get_patches_for_fill'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'prop_cycler'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '157']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '157', 'type': 'block', 'children': ['158', '164', '171', '181', '190', '205', '214']}; {'id': '158', 'type': 'if_statement', 'children': ['159', '162']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'in'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'seg_map'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'continue_statement', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cycler'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'seg_def_style'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '180', 'type': 'argument_list', 'children': []}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '188']}, {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'seg_map'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '197']}; {'id': '192', 'type': 'subscript', 'children': ['193', '196']}, {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'facecolor'"}, {'id': '197', 'type': 'call', 'children': ['198', '203']}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'color'"}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '212']}, {'id': '207', 'type': 'attribute', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'seg_map'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '221']}; {'id': '216', 'type': 'subscript', 'children': ['217', '220']}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'label'"}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '222', 'type': 'for_statement', 'children': ['223', '226', '231']}, {'id': '223', 'type': 'pattern_list', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '231', 'type': 'block', 'children': ['232', '255', '262', '272']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'rect'}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'Rectangle'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '243', '250', '251']}; {'id': '238', 'type': 'tuple', 'children': ['239', '242']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '247'], 'value': '-'}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ival'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '249', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '251', 'type': 'dictionary_splat', 'children': ['252']}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'seg_map'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'add_patch'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '269']}; {'id': '264', 'type': 'attribute', 'children': ['265', '268']}, {'id': '265', 'type': 'subscript', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'string', 'children': [], 'value': "'label'"}, {'id': '271', 'type': 'None', 'children': []}; {'id': '272', 'type': 'if_statement', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '274', 'type': 'block', 'children': ['275', '305']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ann'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'annotate'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284', '291', '294', '300', '303']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'xy'}; {'id': '286', 'type': 'tuple', 'children': ['287', '290']}, {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '289', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'xycoords'}, {'id': '293', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'xytext'}; {'id': '296', 'type': 'tuple', 'children': ['297', '298']}, {'id': '297', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '298', 'type': 'unary_operator', 'children': ['299'], 'value': '-'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'textcoords'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'offset points'"}, {'id': '303', 'type': 'dictionary_splat', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'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': 'ann'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'set_clip_path'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'rect'}; {'id': '312', 'type': 'if_statement', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'new_axes'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'set_yticks'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '322', 'type': 'if_statement', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '__expand_limits'}; {'id': '330', 'type': 'argument_list', 'children': ['331', '332', '343']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '332', 'type': 'list', 'children': ['333', '338'], 'value': '[intervals.min(), intervals.max()]'}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '337', 'type': 'argument_list', 'children': []}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '342', 'type': 'argument_list', 'children': []}, {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '345', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '346', 'type': 'return_statement', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'ax'} | def segments(intervals, labels, base=None, height=None, text=False,
text_kw=None, ax=None, **kwargs):
'''Plot a segmentation as a set of disjoint rectangles.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
base : number
The vertical position of the base of the rectangles.
By default, this will be the bottom of the plot.
height : number
The height of the rectangles.
By default, this will be the top of the plot (minus ``base``).
text : bool
If true, each segment's label is displayed in its
upper-left corner
text_kw : dict
If ``text == True``, the properties of the text
object can be specified here.
See ``matplotlib.pyplot.Text`` for valid parameters
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to pass to
``matplotlib.patches.Rectangle``.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
if text_kw is None:
text_kw = dict()
text_kw.setdefault('va', 'top')
text_kw.setdefault('clip_on', True)
text_kw.setdefault('bbox', dict(boxstyle='round', facecolor='white'))
intervals = np.atleast_2d(intervals)
seg_def_style = dict(linewidth=1)
ax, new_axes = __get_axes(ax=ax)
if new_axes:
ax.set_ylim([0, 1])
if base is None:
base = ax.get_ylim()[0]
if height is None:
height = ax.get_ylim()[1]
cycler = ax._get_patches_for_fill.prop_cycler
seg_map = dict()
for lab in labels:
if lab in seg_map:
continue
style = next(cycler)
seg_map[lab] = seg_def_style.copy()
seg_map[lab].update(style)
seg_map[lab]['facecolor'] = seg_map[lab].pop('color')
seg_map[lab].update(kwargs)
seg_map[lab]['label'] = lab
for ival, lab in zip(intervals, labels):
rect = Rectangle((ival[0], base), ival[1] - ival[0], height,
**seg_map[lab])
ax.add_patch(rect)
seg_map[lab].pop('label', None)
if text:
ann = ax.annotate(lab,
xy=(ival[0], height), xycoords='data',
xytext=(8, -10), textcoords='offset points',
**text_kw)
ann.set_clip_path(rect)
if new_axes:
ax.set_yticks([])
if intervals.size:
__expand_limits(ax, [intervals.min(), intervals.max()], which='x')
return ax |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'labeled_intervals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'extend_labels'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tick'}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'dictionary_splat_pattern', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'block', 'children': ['27', '29', '40', '49', '90', '129', '138', '152', '163', '170', '187', '196', '215', '221', '241', '248', '283', '312', '333', '383', '410', '434']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'''Plot labeled intervals with each label on its own row.\n Parameters\n ----------\n intervals : np.ndarray, shape=(n, 2)\n segment intervals, in the format returned by\n :func:`mir_eval.io.load_intervals` or\n :func:`mir_eval.io.load_labeled_intervals`.\n labels : list, shape=(n,)\n reference segment labels, in the format returned by\n :func:`mir_eval.io.load_labeled_intervals`.\n label_set : list\n An (ordered) list of labels to determine the plotting order.\n If not provided, the labels will be inferred from\n ``ax.get_yticklabels()``.\n If no ``yticklabels`` exist, then the sorted set of unique values\n in ``labels`` is taken as the label set.\n base : np.ndarray, shape=(n,), optional\n Vertical positions of each label.\n By default, labels are positioned at integers\n ``np.arange(len(labels))``.\n height : scalar or np.ndarray, shape=(n,), optional\n Height for each label.\n If scalar, the same value is applied to all labels.\n By default, each label has ``height=1``.\n extend_labels : bool\n If ``False``, only values of ``labels`` that also exist in\n ``label_set`` will be shown.\n If ``True``, all labels are shown, with those in `labels` but\n not in `label_set` appended to the top of the plot.\n A horizontal line is drawn to indicate the separation between\n values in or out of ``label_set``.\n ax : matplotlib.pyplot.axes\n An axis handle on which to draw the intervals.\n If none is provided, a new set of axes is created.\n tick : bool\n If ``True``, sets tick positions and labels on the y-axis.\n kwargs\n Additional keyword arguments to pass to\n `matplotlib.collection.BrokenBarHCollection`.\n Returns\n -------\n ax : matplotlib.pyplot.axes._subplots.AxesSubplot\n A handle to the (possibly constructed) plot axes\n '''"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'pattern_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '__get_axes'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53', '81']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54', '70']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'label_set'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '63']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_text'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'for_in_clause', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_yticklabels'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76']}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '80', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '81', 'type': 'else_clause', 'children': ['82']}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '92', '110', '117']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'extend_labels'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '+'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '106'], 'value': '-'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'label_set'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'label_set'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'linewidth'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'style'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_get_patches_for_fill'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'prop_cycler'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'facecolor'"}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'color'"}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '173', 'type': 'None', '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': 'base'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '187', 'type': 'if_statement', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'is'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '190', 'type': 'None', 'children': []}, {'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': 'height'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'if_statement', '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': 'isscalar'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'height'}, {'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': 'height'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '*'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ones_like'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'seg_y'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '220', 'type': 'argument_list', 'children': []}, {'id': '221', 'type': 'for_statement', 'children': ['222', '226', '232']}; {'id': '222', 'type': 'pattern_list', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'ybase'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'yheight'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '238']}, {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'seg_y'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '238', 'type': 'tuple', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ybase'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'yheight'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'xvals'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '248', 'type': 'for_statement', 'children': ['249', '252', '257']}, {'id': '249', 'type': 'pattern_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '257', 'type': 'block', 'children': ['258', '264']}; {'id': '258', 'type': 'if_statement', 'children': ['259', '262']}, {'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'not'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'seg_y'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'continue_statement', 'children': []}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '271']}; {'id': '266', 'type': 'attribute', 'children': ['267', '270']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'xvals'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'tuple', 'children': ['273', '276']}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '276', 'type': 'binary_operator', 'children': ['277', '280'], 'value': '-'}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ival'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'ival'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '283', 'type': 'for_statement', 'children': ['284', '285', '286']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'seg_y'}; {'id': '286', 'type': 'block', 'children': ['287', '304']}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'add_collection'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'BrokenBarHCollection'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '299', '302']}; {'id': '296', 'type': 'subscript', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'xvals'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'seg_y'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '302', 'type': 'dictionary_splat', 'children': ['303']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '309', 'type': 'argument_list', 'children': ['310', '311']}; {'id': '310', 'type': 'string', 'children': [], 'value': "'label'"}, {'id': '311', 'type': 'None', 'children': []}; {'id': '312', 'type': 'if_statement', 'children': ['313', '316']}, {'id': '313', 'type': 'comparison_operator', 'children': ['314', '315'], 'value': '!='}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'label_set'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'axhline'}; {'id': '322', 'type': 'argument_list', 'children': ['323', '327', '330']}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'label_set'}, {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '329', 'type': 'string', 'children': [], 'value': "'k'"}; {'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '332', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '333', 'type': 'if_statement', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'tick'}, {'id': '335', 'type': 'block', 'children': ['336', '346', '353', '360', '370']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '341', 'type': 'argument_list', 'children': ['342', '343']}; {'id': '342', 'type': 'True', 'children': []}, {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '345', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'call', 'children': ['348', '351']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'set_yticks'}, {'id': '351', 'type': 'argument_list', 'children': ['352']}; {'id': '352', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'call', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'set_yticks'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'}, {'id': '365', 'type': 'argument_list', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'va'}, {'id': '369', 'type': 'string', 'children': [], 'value': "'bottom'"}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}, {'id': '371', 'type': 'call', 'children': ['372', '377']}; {'id': '372', 'type': 'attribute', 'children': ['373', '376']}, {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'yaxis'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'set_major_formatter'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'call', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'IntervalFormatter'}; {'id': '380', 'type': 'argument_list', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '383', 'type': 'if_statement', 'children': ['384', '387']}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '387', 'type': 'block', 'children': ['388']}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'call', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': '__expand_limits'}, {'id': '391', 'type': 'argument_list', 'children': ['392', '393', '407']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '393', 'type': 'list', 'children': ['394', '399'], 'value': '[base.min(), (base + height).max()]'}; {'id': '394', 'type': 'call', 'children': ['395', '398']}, {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '398', 'type': 'argument_list', 'children': []}, {'id': '399', 'type': 'call', 'children': ['400', '406']}; {'id': '400', 'type': 'attribute', 'children': ['401', '405']}, {'id': '401', 'type': 'parenthesized_expression', 'children': ['402']}; {'id': '402', 'type': 'binary_operator', 'children': ['403', '404'], 'value': '+'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '406', 'type': 'argument_list', 'children': []}, {'id': '407', 'type': 'keyword_argument', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '409', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '410', 'type': 'if_statement', 'children': ['411', '414']}, {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '414', 'type': 'block', 'children': ['415']}, {'id': '415', 'type': 'expression_statement', 'children': ['416']}; {'id': '416', 'type': 'call', 'children': ['417', '418']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': '__expand_limits'}; {'id': '418', 'type': 'argument_list', 'children': ['419', '420', '431']}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '420', 'type': 'list', 'children': ['421', '426'], 'value': '[intervals.min(), intervals.max()]'}, {'id': '421', 'type': 'call', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '425', 'type': 'argument_list', 'children': []}; {'id': '426', 'type': 'call', 'children': ['427', '430']}, {'id': '427', 'type': 'attribute', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '430', 'type': 'argument_list', 'children': []}, {'id': '431', 'type': 'keyword_argument', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '433', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '434', 'type': 'return_statement', 'children': ['435']}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'ax'} | def labeled_intervals(intervals, labels, label_set=None,
base=None, height=None, extend_labels=True,
ax=None, tick=True, **kwargs):
'''Plot labeled intervals with each label on its own row.
Parameters
----------
intervals : np.ndarray, shape=(n, 2)
segment intervals, in the format returned by
:func:`mir_eval.io.load_intervals` or
:func:`mir_eval.io.load_labeled_intervals`.
labels : list, shape=(n,)
reference segment labels, in the format returned by
:func:`mir_eval.io.load_labeled_intervals`.
label_set : list
An (ordered) list of labels to determine the plotting order.
If not provided, the labels will be inferred from
``ax.get_yticklabels()``.
If no ``yticklabels`` exist, then the sorted set of unique values
in ``labels`` is taken as the label set.
base : np.ndarray, shape=(n,), optional
Vertical positions of each label.
By default, labels are positioned at integers
``np.arange(len(labels))``.
height : scalar or np.ndarray, shape=(n,), optional
Height for each label.
If scalar, the same value is applied to all labels.
By default, each label has ``height=1``.
extend_labels : bool
If ``False``, only values of ``labels`` that also exist in
``label_set`` will be shown.
If ``True``, all labels are shown, with those in `labels` but
not in `label_set` appended to the top of the plot.
A horizontal line is drawn to indicate the separation between
values in or out of ``label_set``.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the intervals.
If none is provided, a new set of axes is created.
tick : bool
If ``True``, sets tick positions and labels on the y-axis.
kwargs
Additional keyword arguments to pass to
`matplotlib.collection.BrokenBarHCollection`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
ax, _ = __get_axes(ax=ax)
intervals = np.atleast_2d(intervals)
if label_set is None:
label_set = [_.get_text() for _ in ax.get_yticklabels()]
if not any(label_set):
label_set = []
else:
label_set = list(label_set)
if extend_labels:
ticks = label_set + sorted(set(labels) - set(label_set))
elif label_set:
ticks = label_set
else:
ticks = sorted(set(labels))
style = dict(linewidth=1)
style.update(next(ax._get_patches_for_fill.prop_cycler))
style['facecolor'] = style.pop('color')
style.update(kwargs)
if base is None:
base = np.arange(len(ticks))
if height is None:
height = 1
if np.isscalar(height):
height = height * np.ones_like(base)
seg_y = dict()
for ybase, yheight, lab in zip(base, height, ticks):
seg_y[lab] = (ybase, yheight)
xvals = defaultdict(list)
for ival, lab in zip(intervals, labels):
if lab not in seg_y:
continue
xvals[lab].append((ival[0], ival[1] - ival[0]))
for lab in seg_y:
ax.add_collection(BrokenBarHCollection(xvals[lab], seg_y[lab],
**style))
style.pop('label', None)
if label_set != ticks:
ax.axhline(len(label_set), color='k', alpha=0.5)
if tick:
ax.grid(True, axis='y')
ax.set_yticks([])
ax.set_yticks(base)
ax.set_yticklabels(ticks, va='bottom')
ax.yaxis.set_major_formatter(IntervalFormatter(base, ticks))
if base.size:
__expand_limits(ax, [base.min(), (base + height).max()], which='y')
if intervals.size:
__expand_limits(ax, [intervals.min(), intervals.max()], which='x')
return ax |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'events'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '25', '36', '44', '52', '68', '77', '88', '150', '158', '169', '176', '189', '204', '253', '263', '276', '300']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'''Plot event times as a set of vertical lines\n Parameters\n ----------\n times : np.ndarray, shape=(n,)\n event times, in the format returned by\n :func:`mir_eval.io.load_events` or\n :func:`mir_eval.io.load_labeled_events`.\n labels : list, shape=(n,), optional\n event labels, in the format returned by\n :func:`mir_eval.io.load_labeled_events`.\n base : number\n The vertical position of the base of the line.\n By default, this will be the bottom of the plot.\n height : number\n The height of the lines.\n By default, this will be the top of the plot (minus `base`).\n ax : matplotlib.pyplot.axes\n An axis handle on which to draw the segmentation.\n If none is provided, a new set of axes is created.\n text_kw : dict\n If `labels` is provided, the properties of the text\n objects can be specified here.\n See `matplotlib.pyplot.Text` for valid parameters\n kwargs\n Additional keyword arguments to pass to\n `matplotlib.pyplot.vlines`.\n Returns\n -------\n ax : matplotlib.pyplot.axes._subplots.AxesSubplot\n A handle to the (possibly constructed) plot axes\n '''"}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'text_kw'}; {'id': '28', 'type': 'None', 'children': []}, {'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': 'text_kw'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'text_kw'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'va'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'top'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'text_kw'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'clip_on'"}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'text_kw'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'bbox'"}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'boxstyle'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'round'"}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'facecolor'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'white'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'new_axes'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '__get_axes'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90', '118']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'new_axes'}; {'id': '90', 'type': 'block', 'children': ['91', '100', '109']}, {'id': '91', 'type': 'if_statement', 'children': ['92', '95']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'ax'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'set_ylim'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'list', 'children': ['116', '117'], 'value': '[base, height]'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '118', 'type': 'else_clause', 'children': ['119']}, {'id': '119', 'type': 'block', 'children': ['120', '135']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '128', 'type': 'subscript', 'children': ['129', '134']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'get_ylim'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '139']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'is'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'height'}; {'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': 'height'}, {'id': '143', 'type': 'subscript', 'children': ['144', '149']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_ylim'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cycler'}, {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_get_patches_for_fill'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'prop_cycler'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '161', 'type': 'call', 'children': ['162', '168']}; {'id': '162', 'type': 'attribute', 'children': ['163', '167']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cycler'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'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': 'style'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '180']}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'in'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'colors'"}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}, {'id': '187', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '188', 'type': 'None', 'children': []}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'vlines'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198', '199', '202']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '+'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '202', 'type': 'dictionary_splat', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'for_statement', 'children': ['208', '211', '220']}; {'id': '208', 'type': 'pattern_list', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'lab'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '219']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'get_paths'}; {'id': '218', 'type': 'argument_list', 'children': []}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'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': 'ax'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'annotate'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228', '239', '242', '248', '251']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'lab'}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'xy'}; {'id': '230', 'type': 'tuple', 'children': ['231', '238']}, {'id': '231', 'type': 'subscript', 'children': ['232', '237']}; {'id': '232', 'type': 'subscript', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'xycoords'}, {'id': '241', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'xytext'}; {'id': '244', 'type': 'tuple', 'children': ['245', '246']}, {'id': '245', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '246', 'type': 'unary_operator', 'children': ['247'], 'value': '-'}, {'id': '247', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'textcoords'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'offset points'"}, {'id': '251', 'type': 'dictionary_splat', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'text_kw'}, {'id': '253', 'type': 'if_statement', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'new_axes'}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'set_yticks'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': '__expand_limits'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '268', '273']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '268', 'type': 'list', 'children': ['269', '270'], 'value': '[base, base + height]'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '275', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '276', 'type': 'if_statement', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'size'}; {'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': '__expand_limits'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286', '297']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '286', 'type': 'list', 'children': ['287', '292'], 'value': '[times.min(), times.max()]'}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '291', 'type': 'argument_list', 'children': []}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '296', 'type': 'argument_list', 'children': []}, {'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '300', 'type': 'return_statement', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ax'} | def events(times, labels=None, base=None, height=None, ax=None, text_kw=None,
**kwargs):
'''Plot event times as a set of vertical lines
Parameters
----------
times : np.ndarray, shape=(n,)
event times, in the format returned by
:func:`mir_eval.io.load_events` or
:func:`mir_eval.io.load_labeled_events`.
labels : list, shape=(n,), optional
event labels, in the format returned by
:func:`mir_eval.io.load_labeled_events`.
base : number
The vertical position of the base of the line.
By default, this will be the bottom of the plot.
height : number
The height of the lines.
By default, this will be the top of the plot (minus `base`).
ax : matplotlib.pyplot.axes
An axis handle on which to draw the segmentation.
If none is provided, a new set of axes is created.
text_kw : dict
If `labels` is provided, the properties of the text
objects can be specified here.
See `matplotlib.pyplot.Text` for valid parameters
kwargs
Additional keyword arguments to pass to
`matplotlib.pyplot.vlines`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
if text_kw is None:
text_kw = dict()
text_kw.setdefault('va', 'top')
text_kw.setdefault('clip_on', True)
text_kw.setdefault('bbox', dict(boxstyle='round', facecolor='white'))
times = np.asarray(times)
ax, new_axes = __get_axes(ax=ax)
if new_axes:
if base is None:
base = 0
if height is None:
height = 1
ax.set_ylim([base, height])
else:
if base is None:
base = ax.get_ylim()[0]
if height is None:
height = ax.get_ylim()[1]
cycler = ax._get_patches_for_fill.prop_cycler
style = next(cycler).copy()
style.update(kwargs)
if 'colors' in style:
style.pop('color', None)
lines = ax.vlines(times, base, base + height, **style)
if labels:
for path, lab in zip(lines.get_paths(), labels):
ax.annotate(lab,
xy=(path.vertices[0][0], height),
xycoords='data',
xytext=(8, -10), textcoords='offset points',
**text_kw)
if new_axes:
ax.set_yticks([])
__expand_limits(ax, [base, base + height], which='y')
if times.size:
__expand_limits(ax, [times.min(), times.max()], which='x')
return ax |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pitch'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'midi'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'unvoiced'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '17', 'type': 'block', 'children': ['18', '20', '31', '40', '59', '81', '103', '111', '161', '167', '181', '188', '220', '246', '281']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'''Visualize pitch contours\n Parameters\n ----------\n times : np.ndarray, shape=(n,)\n Sample times of frequencies\n frequencies : np.ndarray, shape=(n,)\n frequencies (in Hz) of the pitch contours.\n Voicing is indicated by sign (positive for voiced,\n non-positive for non-voiced).\n midi : bool\n If `True`, plot on a MIDI-numbered vertical axis.\n Otherwise, plot on a linear frequency axis.\n unvoiced : bool\n If `True`, unvoiced pitch contours are plotted and indicated\n by transparency.\n Otherwise, unvoiced pitch contours are omitted from the display.\n ax : matplotlib.pyplot.axes\n An axis handle on which to draw the pitch contours.\n If none is provided, a new set of axes is created.\n kwargs\n Additional keyword arguments to `matplotlib.pyplot.plot`.\n Returns\n -------\n ax : matplotlib.pyplot.axes._subplots.AxesSubplot\n A handle to the (possibly constructed) plot axes\n '''"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__get_axes'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'voicings'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'freq_to_voicing'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v_changes'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '75'], 'value': '!='}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'voicings'}; {'id': '72', 'type': 'slice', 'children': ['73', '74']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'voicings'}, {'id': '77', 'type': 'slice', 'children': ['78', '79']}; {'id': '78', 'type': 'colon', 'children': []}, {'id': '79', 'type': 'unary_operator', 'children': ['80'], 'value': '-'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'v_changes'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'concatenate'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'list', 'children': ['95', '97', '98'], 'value': '[[0], v_changes, [len(voicings)]]'}, {'id': '95', 'type': 'list', 'children': ['96'], 'value': '[0]'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'v_changes'}; {'id': '98', 'type': 'list', 'children': ['99'], 'value': '[len(voicings)]'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'voicings'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'v_slices'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'u_slices'}; {'id': '108', 'type': 'expression_list', 'children': ['109', '110']}, {'id': '109', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '110', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '111', 'type': 'for_statement', 'children': ['112', '115', '124']}; {'id': '112', 'type': 'pattern_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'v_changes'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'v_changes'}, {'id': '121', 'type': 'slice', 'children': ['122', '123']}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'colon', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125', '133']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'slice'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137', '145']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'voicings'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'start'}, {'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': 'v_slices'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '145', 'type': 'elif_clause', 'children': ['146', '153']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '152', 'type': 'argument_list', 'children': []}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'u_slices'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '166', 'type': 'argument_list', 'children': []}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'attribute', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_get_lines'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'prop_cycler'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'midi'}; {'id': '190', 'type': 'block', 'children': ['191', '197', '208']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '>'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'hz_to_midi'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'yaxis'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'set_minor_locator'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'MultipleLocator'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '220', 'type': 'for_statement', 'children': ['221', '222', '223']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'v_slices'}, {'id': '223', 'type': 'block', 'children': ['224', '238']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'plot'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '233', '236']}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '236', 'type': 'dictionary_splat', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'label'"}, {'id': '245', 'type': 'None', 'children': []}; {'id': '246', 'type': 'if_statement', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'unvoiced'}; {'id': '248', 'type': 'block', 'children': ['249', '263']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'alpha'"}; {'id': '254', 'type': 'binary_operator', 'children': ['255', '262'], 'value': '*'}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'alpha'"}, {'id': '261', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '262', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '263', 'type': 'for_statement', 'children': ['264', '265', '266']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'u_slices'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'plot'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '276', '279']}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '279', 'type': 'dictionary_splat', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '281', 'type': 'return_statement', 'children': ['282']} | def pitch(times, frequencies, midi=False, unvoiced=False, ax=None, **kwargs):
'''Visualize pitch contours
Parameters
----------
times : np.ndarray, shape=(n,)
Sample times of frequencies
frequencies : np.ndarray, shape=(n,)
frequencies (in Hz) of the pitch contours.
Voicing is indicated by sign (positive for voiced,
non-positive for non-voiced).
midi : bool
If `True`, plot on a MIDI-numbered vertical axis.
Otherwise, plot on a linear frequency axis.
unvoiced : bool
If `True`, unvoiced pitch contours are plotted and indicated
by transparency.
Otherwise, unvoiced pitch contours are omitted from the display.
ax : matplotlib.pyplot.axes
An axis handle on which to draw the pitch contours.
If none is provided, a new set of axes is created.
kwargs
Additional keyword arguments to `matplotlib.pyplot.plot`.
Returns
-------
ax : matplotlib.pyplot.axes._subplots.AxesSubplot
A handle to the (possibly constructed) plot axes
'''
ax, _ = __get_axes(ax=ax)
times = np.asarray(times)
frequencies, voicings = freq_to_voicing(np.asarray(frequencies,
dtype=np.float))
v_changes = 1 + np.flatnonzero(voicings[1:] != voicings[:-1])
v_changes = np.unique(np.concatenate([[0], v_changes, [len(voicings)]]))
v_slices, u_slices = [], []
for start, end in zip(v_changes, v_changes[1:]):
idx = slice(start, end)
if voicings[start]:
v_slices.append(idx)
elif frequencies[idx].all():
u_slices.append(idx)
style = dict()
style.update(next(ax._get_lines.prop_cycler))
style.update(kwargs)
if midi:
idx = frequencies > 0
frequencies[idx] = hz_to_midi(frequencies[idx])
ax.yaxis.set_minor_locator(MultipleLocator(1))
for idx in v_slices:
ax.plot(times[idx], frequencies[idx], **style)
style.pop('label', None)
if unvoiced:
style['alpha'] = style.get('alpha', 1.0) * 0.5
for idx in u_slices:
ax.plot(times[idx], frequencies[idx], **style)
return ax |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'import_args'}, {'id': '11', 'type': 'block', 'children': ['12', '27', '58', '79', '87', '104', '110', '114', '172', '201', '236', '290']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'archive'}, {'id': '15', 'type': 'conditional_expression', 'children': ['16', '21', '26'], 'value': 'if'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'archive'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'archive'}, {'id': '25', 'type': 'string', 'children': [], 'value': '"lower"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'archive'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '37', '47']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'is_sync_table'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '35', 'type': 'dictionary_splat', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'import_args'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'SyncTableJobManager'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'FileImportJobManager'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '61', 'type': 'conditional_expression', 'children': ['62', '68', '71', '72'], 'value': 'if'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '70', 'type': 'None', 'children': []}, {'id': '71', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'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': 'import_job'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'dictionary_splat', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'import_args'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '95']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '94'], 'value': 'is'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'import_job'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_id'}, {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'raise_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'CartoException'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': '"Import API returned corrupt job details \\\n when creating dataset"'}; {'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': 'import_job'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'refresh'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'while_statement', 'children': ['115', '141']}, {'id': '115', 'type': 'boolean_operator', 'children': ['116', '128', '129'], 'value': 'or'}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': 'in'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '120', 'type': 'tuple', 'children': ['121', '122', '123', '124', '125', '126', '127']}, {'id': '121', 'type': 'string', 'children': [], 'value': '"enqueued"'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"queued"'}, {'id': '123', 'type': 'string', 'children': [], 'value': '"pending"'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"uploading"'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"unpacking"'}; {'id': '126', 'type': 'string', 'children': [], 'value': '"importing"'}, {'id': '127', 'type': 'string', 'children': [], 'value': '"guessing"'}; {'id': '128', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '129', 'type': 'parenthesized_expression', 'children': ['130']}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '136'], 'value': 'and'}, {'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': 'manager'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'SyncTableJobManager'}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': '=='}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"created"'}, {'id': '141', 'type': 'block', 'children': ['142', '155', '162', '168']}; {'id': '142', 'type': 'if_statement', 'children': ['143', '146']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '>='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'MAX_NUMBER_OF_RETRIES'}; {'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': 'CartoException'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': '"Maximum number of retries exceeded \\\n when polling the import API for \\\n dataset creation"'}, {'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': 'time'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'INTERVAL_BETWEEN_RETRIES_S'}; {'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': 'import_job'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'refresh'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '178']}, {'id': '173', 'type': 'comparison_operator', 'children': ['174', '177'], 'value': '=='}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'import_job'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '177', 'type': 'string', 'children': [], 'value': '"failure"'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'raise_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'CartoException'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '190']}; {'id': '184', 'type': 'attribute', 'children': ['185', '189']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'string', 'children': [], 'value': '"Dataset creation was not successful \\\n because of failed import (error: {error}"'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'import_job'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'get_error_text'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '227']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '221', '222'], 'value': 'or'}, {'id': '203', 'type': 'parenthesized_expression', 'children': ['204']}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '216'], 'value': 'and'}, {'id': '205', 'type': 'boolean_operator', 'children': ['206', '211'], 'value': 'and'}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '!='}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '210', 'type': 'string', 'children': [], 'value': '"complete"'}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '215'], 'value': '!='}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'import_job'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '215', 'type': 'string', 'children': [], 'value': '"created"'}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': '!='}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"success"'}, {'id': '221', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': 'is'}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '226', 'type': 'False', 'children': []}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'raise_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'CartoException'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'string', 'children': [], 'value': '"Dataset creation was not successful \\\n because of unknown import error"'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '249', '256']}, {'id': '237', 'type': 'boolean_operator', 'children': ['238', '243', '244'], 'value': 'and'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'import_job'}; {'id': '242', 'type': 'string', 'children': [], 'value': '"visualization_id"'}, {'id': '243', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': 'is'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}; {'id': '248', 'type': 'None', 'children': []}, {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}; {'id': '256', 'type': 'else_clause', 'children': ['257']}, {'id': '257', 'type': 'block', 'children': ['258', '274']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '261', 'type': 'call', 'children': ['262', '270']}; {'id': '262', 'type': 'attribute', 'children': ['263', '269']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'TableManager'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'import_job'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'table_id'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}, {'id': '277', 'type': 'conditional_expression', 'children': ['278', '285', '286', '289'], 'value': 'if'}; {'id': '278', 'type': 'call', 'children': ['279', '284']}, {'id': '279', 'type': 'attribute', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'table_visualization'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '284', 'type': 'argument_list', 'children': []}, {'id': '285', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': 'is'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '288', 'type': 'None', 'children': []}, {'id': '289', 'type': 'None', 'children': []}; {'id': '290', 'type': 'try_statement', 'children': ['291', '305']}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'return_statement', 'children': ['293']}, {'id': '293', 'type': 'conditional_expression', 'children': ['294', '300', '303', '304'], 'value': 'if'}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'is'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'visualization_id'}; {'id': '302', 'type': 'None', 'children': []}, {'id': '303', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '304', 'type': 'None', 'children': []}, {'id': '305', 'type': 'except_clause', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'raise_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'CartoException'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}, {'id': '315', 'type': 'string', 'children': [], 'value': '"Dataset creation was not successful \\\n because of unknown error"'} | def create(self, archive, interval=None, **import_args):
archive = archive.lower() if hasattr(archive, "lower") else archive
if self.is_sync_table(archive, interval, **import_args):
manager = SyncTableJobManager(self.client)
else:
manager = FileImportJobManager(self.client)
import_job = manager.create(archive) if interval is None \
else manager.create(archive, interval)
import_job.run(**import_args)
if import_job.get_id() is None:
raise CartoException(_("Import API returned corrupt job details \
when creating dataset"))
import_job.refresh()
count = 0
while import_job.state in ("enqueued", "queued", "pending", "uploading",
"unpacking", "importing", "guessing") \
or (isinstance(manager, SyncTableJobManager)
and import_job.state == "created"):
if count >= MAX_NUMBER_OF_RETRIES:
raise CartoException(_("Maximum number of retries exceeded \
when polling the import API for \
dataset creation"))
time.sleep(INTERVAL_BETWEEN_RETRIES_S)
import_job.refresh()
count += 1
if import_job.state == "failure":
raise CartoException(_("Dataset creation was not successful \
because of failed import (error: {error}")
.format(error=json.dumps(
import_job.get_error_text)))
if (import_job.state != "complete" and import_job.state != "created"
and import_job.state != "success") \
or import_job.success is False:
raise CartoException(_("Dataset creation was not successful \
because of unknown import error"))
if hasattr(import_job, "visualization_id") \
and import_job.visualization_id is not None:
visualization_id = import_job.visualization_id
else:
table = TableManager(self.client).get(import_job.table_id)
visualization_id = table.table_visualization.get_id() \
if table is not None else None
try:
return self.get(visualization_id) if visualization_id is not None \
else None
except AttributeError:
raise CartoException(_("Dataset creation was not successful \
because of unknown error")) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'blocksize'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'infp'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'outfp'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15', '48']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n A utility function to copy data from the input file object to the output\n file object. This function will use the most efficient copy method available,\n which is often sendfile.\n Parameters:\n data_length - The amount of data to copy.\n blocksize - How much data to copy per iteration.\n infp - The file object to copy data from.\n outfp - The file object to copy data to.\n Returns:\n Nothing.\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'use_sendfile'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'have_sendfile'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'try_statement', 'children': ['19', '40']}, {'id': '19', 'type': 'block', 'children': ['20', '28', '36']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'x_unused'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'infp'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fileno'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'y_unused'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'outfp'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fileno'}, {'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': 'use_sendfile'}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'except_clause', 'children': ['41', '46']}, {'id': '41', 'type': 'tuple', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'io'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'UnsupportedOperation'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'pass_statement', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50', '101']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'use_sendfile'}; {'id': '50', 'type': 'block', 'children': ['51', '59', '67', '83', '92']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'in_offset'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'infp'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'out_offset'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sendfile'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '76', '81', '82']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'outfp'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'fileno'}, {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'infp'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'in_offset'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'infp'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'in_offset'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'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': 'outfp'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'seek'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '+'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'out_offset'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103', '107', '111']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'readsize'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'blocksize'}, {'id': '111', 'type': 'while_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '>'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '115', 'type': 'block', 'children': ['116', '125', '134', '141', '150', '157']}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '<'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'readsize'}; {'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': 'readsize'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'infp'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'readsize'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'data_len'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '141', 'type': 'if_statement', 'children': ['142', '145']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '!='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'data_len'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'readsize'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'data_len'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'outfp'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'augmented_assignment', 'children': ['159', '160'], 'value': '-='}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'left'} | def copy_data(data_length, blocksize, infp, outfp):
'''
A utility function to copy data from the input file object to the output
file object. This function will use the most efficient copy method available,
which is often sendfile.
Parameters:
data_length - The amount of data to copy.
blocksize - How much data to copy per iteration.
infp - The file object to copy data from.
outfp - The file object to copy data to.
Returns:
Nothing.
'''
use_sendfile = False
if have_sendfile:
try:
x_unused = infp.fileno()
y_unused = outfp.fileno()
use_sendfile = True
except (AttributeError, io.UnsupportedOperation):
pass
if use_sendfile:
in_offset = infp.tell()
out_offset = outfp.tell()
sendfile(outfp.fileno(), infp.fileno(), in_offset, data_length)
infp.seek(in_offset + data_length)
outfp.seek(out_offset + data_length)
else:
left = data_length
readsize = blocksize
while left > 0:
if left < readsize:
readsize = left
data = infp.read(readsize)
data_len = len(data)
if data_len != readsize:
data_len = left
outfp.write(data)
left -= data_len |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '21', '36', '80', '117', '129', '141', '154', '241', '277', '287', '293', '299']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n A method to parse ISO hybridization info out of an existing ISO.\n Parameters:\n instr - The data for the ISO hybridization.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'This IsoHybrid object is already initialized'"}, {'id': '21', 'type': 'if_statement', 'children': ['22', '28']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '!='}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '512'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'Invalid size of the instr'"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '47', '56', '76']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '44'], 'value': '=='}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '40', 'type': 'slice', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'colon', 'children': []}, {'id': '43', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ORIG_HEADER'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ORIG_HEADER'}; {'id': '56', 'type': 'elif_clause', 'children': ['57', '67']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '64'], 'value': '=='}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '60', 'type': 'slice', 'children': ['61', '62', '63']}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'colon', 'children': []}, {'id': '63', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'MAC_AFP'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'MAC_AFP'}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'False', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '94']}; {'id': '82', 'type': 'tuple_pattern', 'children': ['83', '86', '89', '90', '93']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'mbr'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'rba'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'unused1'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'unused2'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '102', '116']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'FMT'}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '104', 'type': 'slice', 'children': ['105', '106']}, {'id': '105', 'type': 'colon', 'children': []}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'calcsize'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'FMT'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '32'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '!='}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'unused1'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'raise_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'Invalid IsoHybrid section'"}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '!='}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'unused2'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'raise_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Invalid IsoHybrid section'"}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '+'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'calcsize'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'FMT'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '161', '232']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '161', 'type': 'block', 'children': ['162', '228']}; {'id': '162', 'type': 'if_statement', 'children': ['163', '175']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '174'], 'value': '=='}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'bytearray'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'list', 'children': ['171'], 'value': '[instr[offset]]'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '174', 'type': 'string', 'children': [], 'value': "b'\\x80'"}, {'id': '175', 'type': 'block', 'children': ['176', '182', '227']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'part_entry'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '213']}; {'id': '184', 'type': 'tuple_pattern', 'children': ['185', '186', '189', '192', '195', '198', '201', '204', '207', '210']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'const_unused'}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'bhead'}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'bsect'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'bcyle'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'ptype'}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ehead'}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'esect'}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ecyle'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'part_offset'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'psize'}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '219', '226']}; {'id': '218', 'type': 'string', 'children': [], 'value': "'=BBBBBBBBLL'"}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '221', 'type': 'slice', 'children': ['222', '223']}; {'id': '222', 'type': 'colon', 'children': []}, {'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '+'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '227', 'type': 'break_statement', 'children': []}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '+='}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '232', 'type': 'else_clause', 'children': ['233']}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'raise_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'No valid partition found in IsoHybrid!'"}, {'id': '241', 'type': 'if_statement', 'children': ['242', '269']}; {'id': '242', 'type': 'boolean_operator', 'children': ['243', '256'], 'value': 'or'}, {'id': '243', 'type': 'comparison_operator', 'children': ['244', '255'], 'value': '!='}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'bytearray'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'list', 'children': ['251'], 'value': '[instr[-2]]'}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '253', 'type': 'unary_operator', 'children': ['254'], 'value': '-'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '255', 'type': 'string', 'children': [], 'value': "b'\\x55'"}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '268'], 'value': '!='}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'bytes'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'bytearray'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'list', 'children': ['264'], 'value': '[instr[-1]]'}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '266', 'type': 'unary_operator', 'children': ['267'], 'value': '-'}, {'id': '267', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '268', 'type': 'string', 'children': [], 'value': "b'\\xaa'"}, {'id': '269', 'type': 'block', 'children': ['270']}; {'id': '270', 'type': 'raise_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'string', 'children': [], 'value': "'Invalid tail on isohybrid section'"}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}; {'id': '282', 'type': 'binary_operator', 'children': ['283', '286'], 'value': '+'}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'ehead'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}; {'id': '292', 'type': 'integer', 'children': [], 'value': '32'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': '_initialized'}; {'id': '298', 'type': 'True', 'children': []}, {'id': '299', 'type': 'return_statement', 'children': ['300']} | def parse(self, instr):
'''
A method to parse ISO hybridization info out of an existing ISO.
Parameters:
instr - The data for the ISO hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if len(instr) != 512:
raise pycdlibexception.PyCdlibInvalidISO('Invalid size of the instr')
if instr[0:32] == self.ORIG_HEADER:
self.header = self.ORIG_HEADER
elif instr[0:32] == self.MAC_AFP:
self.header = self.MAC_AFP
else:
return False
(self.mbr, self.rba, unused1, self.mbr_id,
unused2) = struct.unpack_from(self.FMT, instr[:32 + struct.calcsize(self.FMT)], 32)
if unused1 != 0:
raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section')
if unused2 != 0:
raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section')
offset = 32 + struct.calcsize(self.FMT)
for i in range(1, 5):
if bytes(bytearray([instr[offset]])) == b'\x80':
self.part_entry = i
(const_unused, self.bhead, self.bsect, self.bcyle, self.ptype,
self.ehead, self.esect, self.ecyle, self.part_offset,
self.psize) = struct.unpack_from('=BBBBBBBBLL', instr[:offset + 16], offset)
break
offset += 16
else:
raise pycdlibexception.PyCdlibInvalidISO('No valid partition found in IsoHybrid!')
if bytes(bytearray([instr[-2]])) != b'\x55' or bytes(bytearray([instr[-1]])) != b'\xaa':
raise pycdlibexception.PyCdlibInvalidISO('Invalid tail on isohybrid section')
self.geometry_heads = self.ehead + 1
self.geometry_sectors = 32
self._initialized = True
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'new'}, {'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': 'mac'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'part_entry'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'part_offset'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'part_type'}; {'id': '12', 'type': 'block', 'children': ['13', '15', '27', '48', '52', '58', '64', '70', '88', '94', '105', '116', '127', '140', '146', '152', '160', '166', '172', '178']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'''\n A method to add ISO hybridization to an ISO.\n Parameters:\n mac - Whether this ISO should be made bootable for the Macintosh.\n part_entry - The partition entry for the hybridization.\n mbr_id - The mbr_id to use for the hybridization.\n part_offset - The partition offset to use for the hybridization.\n geometry_sectors - The number of sectors to use for the hybridization.\n geometry_heads - The number of heads to use for the hybridization.\n part_type - The partition type for the hybridization.\n Returns:\n Nothing.\n '''"}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'raise_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'This IsoHybrid object is already initialized'"}, {'id': '27', 'type': 'if_statement', 'children': ['28', '29', '38']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'mac'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'MAC_AFP'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ORIG_HEADER'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isohybrid_data_hd0'}, {'id': '51', 'type': 'string', 'children': [], 'value': "b'\\x33\\xed\\xfa\\x8e\\xd5\\xbc\\x00\\x7c\\xfb\\xfc\\x66\\x31\\xdb\\x66\\x31\\xc9\\x66\\x53\\x66\\x51\\x06\\x57\\x8e\\xdd\\x8e\\xc5\\x52\\xbe\\x00\\x7c\\xbf\\x00\\x06\\xb9\\x00\\x01\\xf3\\xa5\\xea\\x4b\\x06\\x00\\x00\\x52\\xb4\\x41\\xbb\\xaa\\x55\\x31\\xc9\\x30\\xf6\\xf9\\xcd\\x13\\x72\\x16\\x81\\xfb\\x55\\xaa\\x75\\x10\\x83\\xe1\\x01\\x74\\x0b\\x66\\xc7\\x06\\xf1\\x06\\xb4\\x42\\xeb\\x15\\xeb\\x00\\x5a\\x51\\xb4\\x08\\xcd\\x13\\x83\\xe1\\x3f\\x5b\\x51\\x0f\\xb6\\xc6\\x40\\x50\\xf7\\xe1\\x53\\x52\\x50\\xbb\\x00\\x7c\\xb9\\x04\\x00\\x66\\xa1\\xb0\\x07\\xe8\\x44\\x00\\x0f\\x82\\x80\\x00\\x66\\x40\\x80\\xc7\\x02\\xe2\\xf2\\x66\\x81\\x3e\\x40\\x7c\\xfb\\xc0\\x78\\x70\\x75\\x09\\xfa\\xbc\\xec\\x7b\\xea\\x44\\x7c\\x00\\x00\\xe8\\x83\\x00\\x69\\x73\\x6f\\x6c\\x69\\x6e\\x75\\x78\\x2e\\x62\\x69\\x6e\\x20\\x6d\\x69\\x73\\x73\\x69\\x6e\\x67\\x20\\x6f\\x72\\x20\\x63\\x6f\\x72\\x72\\x75\\x70\\x74\\x2e\\x0d\\x0a\\x66\\x60\\x66\\x31\\xd2\\x66\\x03\\x06\\xf8\\x7b\\x66\\x13\\x16\\xfc\\x7b\\x66\\x52\\x66\\x50\\x06\\x53\\x6a\\x01\\x6a\\x10\\x89\\xe6\\x66\\xf7\\x36\\xe8\\x7b\\xc0\\xe4\\x06\\x88\\xe1\\x88\\xc5\\x92\\xf6\\x36\\xee\\x7b\\x88\\xc6\\x08\\xe1\\x41\\xb8\\x01\\x02\\x8a\\x16\\xf2\\x7b\\xcd\\x13\\x8d\\x64\\x10\\x66\\x61\\xc3\\xe8\\x1e\\x00\\x4f\\x70\\x65\\x72\\x61\\x74\\x69\\x6e\\x67\\x20\\x73\\x79\\x73\\x74\\x65\\x6d\\x20\\x6c\\x6f\\x61\\x64\\x20\\x65\\x72\\x72\\x6f\\x72\\x2e\\x0d\\x0a\\x5e\\xac\\xb4\\x0e\\x8a\\x3e\\x62\\x04\\xb3\\x07\\xcd\\x10\\x3c\\x0a\\x75\\xf1\\xcd\\x18\\xf4\\xeb\\xfd\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'mbr'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isohybrid_data_hd0'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rba'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': 'is'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}, {'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': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'mbr_id'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'getrandbits'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'part_entry'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'part_entry'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'bhead'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '104'], 'value': '%'}; {'id': '100', 'type': 'parenthesized_expression', 'children': ['101']}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '//'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'part_offset'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'bsect'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '115'], 'value': '+'}, {'id': '111', 'type': 'parenthesized_expression', 'children': ['112']}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'part_offset'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'bcyle'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '//'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'part_offset'}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124']}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '*'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'augmented_assignment', 'children': ['129', '132'], 'value': '+='}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'bsect'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '139'], 'value': '>>'}, {'id': '133', 'type': 'parenthesized_expression', 'children': ['134']}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '138'], 'value': '&'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'bcyle'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0x300'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'augmented_assignment', 'children': ['142', '145'], 'value': '&='}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'bcyle'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '0xff'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ptype'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'part_type'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ehead'}, {'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '-'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'part_offset'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'part_offset'}; {'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': 'geometry_heads'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'geometry_heads'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'geometry_sectors'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '183', 'type': 'True', 'children': []} | def new(self, mac, part_entry, mbr_id, part_offset,
geometry_sectors, geometry_heads, part_type):
'''
A method to add ISO hybridization to an ISO.
Parameters:
mac - Whether this ISO should be made bootable for the Macintosh.
part_entry - The partition entry for the hybridization.
mbr_id - The mbr_id to use for the hybridization.
part_offset - The partition offset to use for the hybridization.
geometry_sectors - The number of sectors to use for the hybridization.
geometry_heads - The number of heads to use for the hybridization.
part_type - The partition type for the hybridization.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if mac:
self.header = self.MAC_AFP
else:
self.header = self.ORIG_HEADER
isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
self.mbr = isohybrid_data_hd0
self.rba = 0
self.mbr_id = mbr_id
if self.mbr_id is None:
self.mbr_id = random.getrandbits(32)
self.part_entry = part_entry
self.bhead = (part_offset // geometry_sectors) % geometry_heads
self.bsect = (part_offset % geometry_sectors) + 1
self.bcyle = part_offset // (geometry_heads * geometry_sectors)
self.bsect += (self.bcyle & 0x300) >> 2
self.bcyle &= 0xff
self.ptype = part_type
self.ehead = geometry_heads - 1
self.part_offset = part_offset
self.geometry_heads = geometry_heads
self.geometry_sectors = geometry_sectors
self._initialized = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_new'}, {'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': 'vd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'seqnum'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'xa'}; {'id': '12', 'type': 'block', 'children': ['13', '15', '25', '33', '49', '55', '61', '67', '73', '79', '90', '107', '113', '129', '135', '141', '147', '153', '164', '193', '204', '251', '257']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'''\n Internal method to create a new Directory Record.\n Parameters:\n vd - The Volume Descriptor this record is part of.\n name - The name for this directory record.\n parent - The parent of this directory record.\n seqnum - The sequence number to associate with this directory record.\n isdir - Whether this directory record represents a directory.\n length - The length of the data for this directory record.\n xa - True if this is an Extended Attribute record.\n Returns:\n Nothing.\n '''"}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dates'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'DirectoryRecordDate'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'expression_statement', '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': 'date'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '41']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '>'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '40'], 'value': '-'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '**'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'Maximum supported file length is 2^32-1'"}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'seqnum'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'seqnum'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'orig_extent_loc'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'len_fi'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dr_len'}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '104'], 'value': '+'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'struct'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'calcsize'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'FMT'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'len_fi'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'file_flags'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '113', 'type': 'if_statement', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '123'], 'value': '|='}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'file_flags'}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124']}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '<<'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'FILE_FLAG_DIRECTORY_BIT'}, {'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': 'file_unit_size'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'interleave_gap_size'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'xattr_len'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'is'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '156', 'type': 'None', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'is_root'}, {'id': '163', 'type': 'True', 'children': []}; {'id': '164', 'type': 'if_statement', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'xa'}; {'id': '166', 'type': 'block', 'children': ['167', '175', '183']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'xa_record'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'XARecord'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '182']}, {'id': '177', 'type': 'attribute', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'xa_record'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '182', 'type': 'argument_list', 'children': []}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'augmented_assignment', 'children': ['185', '188'], 'value': '+='}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'dr_len'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'XARecord'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '192', 'type': 'argument_list', 'children': []}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'augmented_assignment', 'children': ['195', '198'], 'value': '+='}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dr_len'}; {'id': '198', 'type': 'parenthesized_expression', 'children': ['199']}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '203'], 'value': '%'}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'dr_len'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '208', '215', '228', '241']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'is_root'}; {'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': '_printable_name'}; {'id': '214', 'type': 'string', 'children': [], 'value': "b'/'"}, {'id': '215', 'type': 'elif_clause', 'children': ['216', '221']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': '=='}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '220', 'type': 'string', 'children': [], 'value': "b'\\x00'"}, {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_printable_name'}, {'id': '227', 'type': 'string', 'children': [], 'value': "b'.'"}; {'id': '228', 'type': 'elif_clause', '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': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '233', 'type': 'string', 'children': [], 'value': "b'\\x01'"}; {'id': '234', 'type': 'block', 'children': ['235']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': '_printable_name'}; {'id': '240', 'type': 'string', 'children': [], 'value': "b'..'"}, {'id': '241', 'type': 'else_clause', 'children': ['242']}; {'id': '242', 'type': 'block', 'children': ['243']}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '_printable_name'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': '_initialized'} | def _new(self, vd, name, parent, seqnum, isdir, length, xa):
'''
Internal method to create a new Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number to associate with this directory record.
isdir - Whether this directory record represents a directory.
length - The length of the data for this directory record.
xa - True if this is an Extended Attribute record.
Returns:
Nothing.
'''
self.date = dates.DirectoryRecordDate()
self.date.new()
if length > 2**32 - 1:
raise pycdlibexception.PyCdlibInvalidInput('Maximum supported file length is 2^32-1')
self.data_length = length
self.file_ident = name
self.isdir = isdir
self.seqnum = seqnum
self.orig_extent_loc = None
self.len_fi = len(self.file_ident)
self.dr_len = struct.calcsize(self.FMT) + self.len_fi
self.file_flags = 0
if self.isdir:
self.file_flags |= (1 << self.FILE_FLAG_DIRECTORY_BIT)
self.file_unit_size = 0
self.interleave_gap_size = 0
self.xattr_len = 0
self.parent = parent
if parent is None:
self.is_root = True
if xa:
self.xa_record = XARecord()
self.xa_record.new()
self.dr_len += XARecord.length()
self.dr_len += (self.dr_len % 2)
if self.is_root:
self._printable_name = b'/'
elif self.file_ident == b'\x00':
self._printable_name = b'.'
elif self.file_ident == b'\x01':
self._printable_name = b'..'
else:
self._printable_name = self.file_ident
self.vd = vd
self._initialized = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'new_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'seqnum'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'rr_name'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rr_relocated_child'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'rr_relocated'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'xa'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'file_mode'}; {'id': '16', 'type': 'block', 'children': ['17', '19', '31', '44']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'''\n Create a new directory Directory Record.\n Parameters:\n vd - The Volume Descriptor this record is part of.\n name - The name for this directory record.\n parent - The parent of this directory record.\n seqnum - The sequence number for this directory record.\n rock_ridge - Whether to make this a Rock Ridge directory record.\n rr_name - The Rock Ridge name for this directory record.\n log_block_size - The logical block size to use.\n rr_relocated_child - True if this is a Rock Ridge relocated child.\n rr_relocated - True if this is a Rock Ridge relocated entry.\n xa - True if this is an Extended Attribute record.\n file_mode - The POSIX file mode to set for this directory.\n Returns:\n Nothing.\n '''"}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Directory Record already initialized'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_new'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41', '42', '43']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'seqnum'}, {'id': '41', 'type': 'True', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'xa'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '46', 'type': 'block', 'children': ['47', '60']}, {'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': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_rr_new'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56', '57', '58', '59']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rr_name'}, {'id': '55', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rr_relocated_child'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'rr_relocated'}; {'id': '58', 'type': 'False', 'children': []}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'file_mode'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '66']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '63'], 'value': 'and'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rr_relocated_child'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '66', 'type': 'block', 'children': ['67', '73', '79']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '72', 'type': 'False', 'children': []}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'file_flags'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'add_to_file_links'} | def new_dir(self, vd, name, parent, seqnum, rock_ridge, rr_name, log_block_size,
rr_relocated_child, rr_relocated, xa, file_mode):
'''
Create a new directory Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
name - The name for this directory record.
parent - The parent of this directory record.
seqnum - The sequence number for this directory record.
rock_ridge - Whether to make this a Rock Ridge directory record.
rr_name - The Rock Ridge name for this directory record.
log_block_size - The logical block size to use.
rr_relocated_child - True if this is a Rock Ridge relocated child.
rr_relocated - True if this is a Rock Ridge relocated entry.
xa - True if this is an Extended Attribute record.
file_mode - The POSIX file mode to set for this directory.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized')
self._new(vd, name, parent, seqnum, True, log_block_size, xa)
if rock_ridge:
self._rr_new(rock_ridge, rr_name, b'', rr_relocated_child,
rr_relocated, False, file_mode)
if rr_relocated_child and self.rock_ridge:
self.isdir = False
self.file_flags = 0
self.rock_ridge.add_to_file_links() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_child'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'allow_duplicate'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'check_overflow'}, {'id': '9', 'type': 'block', 'children': ['10', '12', '25', '37', '122', '132', '245', '257', '261', '351']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'''\n An internal method to add a child to this object. Note that this is called both\n during parsing and when adding a new object to the system, so it\n it shouldn't have any functionality that is not appropriate for both.\n Parameters:\n child - The child directory record object to add.\n logical_block_size - The size of a logical block for this volume descriptor.\n allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed.\n check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this.\n Returns:\n True if adding this child caused the directory to overflow into another\n extent, False otherwise.\n '''"}; {'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': 'isdir'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Trying to add a child to a record that is not a directory'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bisect'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'bisect_left'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '58']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '47'], 'value': 'and'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '!='}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '55'], 'value': '=='}; {'id': '48', 'type': 'attribute', 'children': ['49', '54']}, {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '77']}; {'id': '60', 'type': 'boolean_operator', 'children': ['61', '71'], 'value': 'and'}, {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '70']}, {'id': '63', 'type': 'attribute', 'children': ['64', '69']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'is_associated_file'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'is_associated_file'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'if_statement', 'children': ['79', '94']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81']}, {'id': '81', 'type': 'boolean_operator', 'children': ['82', '87'], 'value': 'and'}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': 'is'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '86', 'type': 'None', 'children': []}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '93'], 'value': '=='}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'file_identifier'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'string', 'children': [], 'value': "b'RR_MOVED'"}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '98', '106']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'allow_duplicate'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'raise_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'Failed adding duplicate name to parent'"}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108', '118']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '117']}; {'id': '110', 'type': 'attribute', 'children': ['111', '116']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'data_continuation'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '+='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '152']}, {'id': '133', 'type': 'boolean_operator', 'children': ['134', '146'], 'value': 'and'}; {'id': '134', 'type': 'boolean_operator', 'children': ['135', '140'], 'value': 'and'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': 'is'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '139', 'type': 'None', 'children': []}; {'id': '140', 'type': 'not_operator', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'is_dot'}, {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'not_operator', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'is_dotdot'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'block', 'children': ['153', '157', '166', '231', '235']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'rr_children'}; {'id': '166', 'type': 'while_statement', 'children': ['167', '170']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '<'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '170', 'type': 'block', 'children': ['171', '180', '190']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '179'], 'value': '//'}, {'id': '175', 'type': 'parenthesized_expression', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '179', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rr'}, {'id': '183', 'type': 'attribute', 'children': ['184', '189']}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'rr_children'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '194', '222']}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'is'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'rr'}, {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'if_statement', 'children': ['196', '209', '216']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': '<'}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'rr'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '208', 'type': 'argument_list', 'children': []}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '+'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'else_clause', 'children': ['217']}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '222', 'type': 'else_clause', 'children': ['223']}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'raise_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'Expected all children to have Rock Ridge, but one did not'"}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rr_index'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '242']}, {'id': '237', 'type': 'attribute', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'rr_children'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'rr_index'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '250']}, {'id': '247', 'type': 'pattern_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'num_extents'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'offset_unused'}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': '_recalculate_extents_and_offsets'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'overflowed'}; {'id': '260', 'type': 'False', 'children': []}, {'id': '261', 'type': 'if_statement', 'children': ['262', '272']}; {'id': '262', 'type': 'boolean_operator', 'children': ['263', '264'], 'value': 'and'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'check_overflow'}; {'id': '264', 'type': 'parenthesized_expression', 'children': ['265']}, {'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': '>'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '*'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'num_extents'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '272', 'type': 'block', 'children': ['273', '277', '283', '295', '314']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'overflowed'}; {'id': '276', 'type': 'True', 'children': []}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'augmented_assignment', 'children': ['279', '282'], 'value': '+='}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '292']}, {'id': '285', 'type': 'attribute', 'children': ['286', '291']}; {'id': '286', 'type': 'subscript', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '290', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '295', 'type': 'if_statement', 'children': ['296', '301']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '300'], 'value': 'is'}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '300', 'type': 'None', 'children': []}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '311']}; {'id': '304', 'type': 'attribute', 'children': ['305', '310']}, {'id': '305', 'type': 'subscript', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '309', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '314', 'type': 'for_statement', 'children': ['315', '316', '319']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '319', 'type': 'block', 'children': ['320', '329']}; {'id': '320', 'type': 'if_statement', 'children': ['321', '327']}, {'id': '321', 'type': 'not_operator', 'children': ['322']}; {'id': '322', 'type': 'call', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '326', 'type': 'argument_list', 'children': []}, {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'continue_statement', 'children': []}, {'id': '329', 'type': 'if_statement', 'children': ['330', '338']}; {'id': '330', 'type': 'comparison_operator', 'children': ['331', '337'], 'value': '>'}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '337', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '338', 'type': 'block', 'children': ['339']}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'assignment', 'children': ['341', '348']}, {'id': '341', 'type': 'attribute', 'children': ['342', '347']}; {'id': '342', 'type': 'subscript', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '346', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '351', 'type': 'return_statement', 'children': ['352']} | def _add_child(self, child, logical_block_size, allow_duplicate, check_overflow):
'''
An internal method to add a child to this object. Note that this is called both
during parsing and when adding a new object to the system, so it
it shouldn't have any functionality that is not appropriate for both.
Parameters:
child - The child directory record object to add.
logical_block_size - The size of a logical block for this volume descriptor.
allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed.
check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this.
Returns:
True if adding this child caused the directory to overflow into another
extent, False otherwise.
'''
if not self.isdir:
raise pycdlibexception.PyCdlibInvalidInput('Trying to add a child to a record that is not a directory')
index = bisect.bisect_left(self.children, child)
if index != len(self.children) and self.children[index].file_ident == child.file_ident:
if not self.children[index].is_associated_file() and not child.is_associated_file():
if not (self.rock_ridge is not None and self.file_identifier() == b'RR_MOVED'):
if not allow_duplicate:
raise pycdlibexception.PyCdlibInvalidInput('Failed adding duplicate name to parent')
else:
self.children[index].data_continuation = child
index += 1
self.children.insert(index, child)
if child.rock_ridge is not None and not child.is_dot() and not child.is_dotdot():
lo = 0
hi = len(self.rr_children)
while lo < hi:
mid = (lo + hi) // 2
rr = self.rr_children[mid].rock_ridge
if rr is not None:
if rr.name() < child.rock_ridge.name():
lo = mid + 1
else:
hi = mid
else:
raise pycdlibexception.PyCdlibInternalError('Expected all children to have Rock Ridge, but one did not')
rr_index = lo
self.rr_children.insert(rr_index, child)
num_extents, offset_unused = self._recalculate_extents_and_offsets(index,
logical_block_size)
overflowed = False
if check_overflow and (num_extents * logical_block_size > self.data_length):
overflowed = True
self.data_length += logical_block_size
self.children[0].data_length = self.data_length
if self.parent is None:
self.children[1].data_length = self.data_length
for c in self.children:
if not c.is_dir():
continue
if len(c.children) > 1:
c.children[1].data_length = self.data_length
return overflowed |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_child'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '24', '36', '168', '174', '186', '190', '201', '289']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n A method to remove a child from this Directory Record.\n Parameters:\n child - The child DirectoryRecord object to remove.\n index - The index of the child into this DirectoryRecord children list.\n logical_block_size - The size of a logical block on this volume descriptor.\n Returns:\n True if removing this child caused an underflow, False otherwise.\n '''"}, {'id': '11', 'type': 'if_statement', 'children': ['12', '16']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_initialized'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'Directory Record not yet initialized'"}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '<'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'Invalid child index to remove'"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '55']}; {'id': '44', 'type': 'boolean_operator', 'children': ['45', '48'], 'value': 'or'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'child_link_record_exists'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56', '73', '101']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '65']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '64'], 'value': '<'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'raise_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'Expected a dot and dotdot entry, but missing; ISO is corrupt'"}, {'id': '73', 'type': 'if_statement', 'children': ['74', '93']}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '84'], 'value': 'or'}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '83'], 'value': 'is'}; {'id': '76', 'type': 'attribute', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '92'], 'value': 'is'}, {'id': '85', 'type': 'attribute', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '92', 'type': 'None', 'children': []}, {'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': 'pycdlibexception'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'Missing Rock Ridge entry on dot or dotdot; ISO is corrupt'"}, {'id': '101', 'type': 'if_statement', 'children': ['102', '107', '132']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '106'], 'value': 'is'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'block', 'children': ['108', '120']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '119']}; {'id': '110', 'type': 'attribute', 'children': ['111', '118']}, {'id': '111', 'type': 'attribute', 'children': ['112', '117']}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'remove_from_file_links'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '131']}; {'id': '122', 'type': 'attribute', 'children': ['123', '130']}, {'id': '123', 'type': 'attribute', 'children': ['124', '129']}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'remove_from_file_links'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'else_clause', 'children': ['133']}, {'id': '133', 'type': 'block', 'children': ['134', '148', '156']}; {'id': '134', 'type': 'if_statement', 'children': ['135', '140']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': 'is'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '139', 'type': 'None', 'children': []}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'raise_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'Child has Rock Ridge, but parent does not; ISO is corrupt'"}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'remove_from_file_links'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '167']}; {'id': '158', 'type': 'attribute', 'children': ['159', '166']}, {'id': '159', 'type': 'attribute', 'children': ['160', '165']}; {'id': '160', 'type': 'subscript', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'remove_from_file_links'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'delete_statement', 'children': ['169']}, {'id': '169', 'type': 'subscript', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'pattern_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'num_extents'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'dirrecord_offset'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_recalculate_extents_and_offsets'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'underflow'}, {'id': '189', 'type': 'False', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'total_size'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '200'], 'value': '+'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '199'], 'value': '*'}, {'id': '195', 'type': 'parenthesized_expression', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '-'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'num_extents'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'dirrecord_offset'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '210']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '209'], 'value': '>'}, {'id': '203', 'type': 'parenthesized_expression', 'children': ['204']}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '208'], 'value': '-'}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'total_size'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '210', 'type': 'block', 'children': ['211', '217', '229', '248', '285']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'augmented_assignment', 'children': ['213', '216'], 'value': '-='}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '226']}, {'id': '219', 'type': 'attribute', 'children': ['220', '225']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '235']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '234'], 'value': 'is'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '234', 'type': 'None', 'children': []}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '245']}; {'id': '238', 'type': 'attribute', 'children': ['239', '244']}, {'id': '239', 'type': 'subscript', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '248', 'type': 'for_statement', 'children': ['249', '250', '253']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '253', 'type': 'block', 'children': ['254', '263']}; {'id': '254', 'type': 'if_statement', 'children': ['255', '261']}, {'id': '255', 'type': 'not_operator', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '260', 'type': 'argument_list', 'children': []}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'continue_statement', 'children': []}, {'id': '263', 'type': 'if_statement', 'children': ['264', '272']}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '271'], 'value': '>'}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '271', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '282']}, {'id': '275', 'type': 'attribute', 'children': ['276', '281']}; {'id': '276', 'type': 'subscript', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '280', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'data_length'}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'data_length'}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'underflow'}; {'id': '288', 'type': 'True', 'children': []}, {'id': '289', 'type': 'return_statement', 'children': ['290']} | def remove_child(self, child, index, logical_block_size):
'''
A method to remove a child from this Directory Record.
Parameters:
child - The child DirectoryRecord object to remove.
index - The index of the child into this DirectoryRecord children list.
logical_block_size - The size of a logical block on this volume descriptor.
Returns:
True if removing this child caused an underflow, False otherwise.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
if index < 0:
raise pycdlibexception.PyCdlibInternalError('Invalid child index to remove')
if child.rock_ridge is not None:
if child.isdir or child.rock_ridge.child_link_record_exists():
if len(self.children) < 2:
raise pycdlibexception.PyCdlibInvalidISO('Expected a dot and dotdot entry, but missing; ISO is corrupt')
if self.children[0].rock_ridge is None or self.children[1].rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Missing Rock Ridge entry on dot or dotdot; ISO is corrupt')
if self.parent is None:
self.children[0].rock_ridge.remove_from_file_links()
self.children[1].rock_ridge.remove_from_file_links()
else:
if self.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Child has Rock Ridge, but parent does not; ISO is corrupt')
self.rock_ridge.remove_from_file_links()
self.children[0].rock_ridge.remove_from_file_links()
del self.children[index]
num_extents, dirrecord_offset = self._recalculate_extents_and_offsets(index,
logical_block_size)
underflow = False
total_size = (num_extents - 1) * logical_block_size + dirrecord_offset
if (self.data_length - total_size) > logical_block_size:
self.data_length -= logical_block_size
self.children[0].data_length = self.data_length
if self.parent is None:
self.children[1].data_length = self.data_length
for c in self.children:
if not c.is_dir():
continue
if len(c.children) > 1:
c.children[1].data_length = self.data_length
underflow = True
return underflow |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_record'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '13', '33', '53', '70', '93', '110', '130', '150', '170', '190', '207', '227', '247', '264', '284', '304']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Return a string representing the Rock Ridge entry.\n Parameters:\n entries - The dr_entries or ce_entries to generate a record for.\n Returns:\n A string representing the Rock Ridge entry.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'outlist'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sp_record'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'outlist'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'append'}, {'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': 'entries'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sp_record'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '39']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': 'is'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rr_record'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'outlist'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '45', 'type': 'argument_list', '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': 'entries'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rr_record'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'nm_record'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'nm_records'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'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': 'outlist'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'nm_record'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': 'is'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'px_record'}, {'id': '75', 'type': 'None', 'children': []}; {'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': 'outlist'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'px_record'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'rr_version'}, {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '98']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sl_record'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sl_records'}; {'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': 'outlist'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sl_record'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': 'is'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'tf_record'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'tf_record'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': 'is'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cl_record'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'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': 'entries'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cl_record'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '156']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': 'is'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'pl_record'}, {'id': '155', 'type': 'None', 'children': []}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '169']}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'pl_record'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'if_statement', 'children': ['171', '176']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': 'is'}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 're_record'}, {'id': '175', 'type': 'None', 'children': []}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '182', 'type': 'argument_list', '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': 'entries'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 're_record'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'for_statement', 'children': ['191', '192', '195']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'es_record'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'es_records'}, {'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': 'outlist'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'es_record'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '206', 'type': 'argument_list', 'children': []}, {'id': '207', 'type': 'if_statement', 'children': ['208', '213']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': 'is'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'er_record'}; {'id': '212', 'type': 'None', 'children': []}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'outlist'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '219', 'type': 'argument_list', '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': 'entries'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'er_record'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '226', 'type': 'argument_list', 'children': []}, {'id': '227', 'type': 'if_statement', 'children': ['228', '233']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': 'is'}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ce_record'}; {'id': '232', 'type': 'None', 'children': []}, {'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': 'outlist'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'ce_record'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '246', 'type': 'argument_list', 'children': []}, {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '252']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'pd_record'}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'pd_records'}; {'id': '252', 'type': 'block', 'children': ['253']}, {'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': 'outlist'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'pd_record'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '263', 'type': 'argument_list', 'children': []}; {'id': '264', 'type': 'if_statement', 'children': ['265', '270']}, {'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': 'is'}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'st_record'}, {'id': '269', 'type': 'None', 'children': []}; {'id': '270', 'type': 'block', 'children': ['271']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '283']}; {'id': '278', 'type': 'attribute', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'st_record'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '283', 'type': 'argument_list', 'children': []}; {'id': '284', 'type': 'if_statement', 'children': ['285', '290']}, {'id': '285', 'type': 'comparison_operator', 'children': ['286', '289'], 'value': 'is'}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sf_record'}, {'id': '289', 'type': 'None', 'children': []}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'outlist'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '296', 'type': 'argument_list', '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': 'entries'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'sf_record'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'return_statement', 'children': ['305']}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '309', 'type': 'argument_list', 'children': ['310']} | def _record(self, entries):
'''
Return a string representing the Rock Ridge entry.
Parameters:
entries - The dr_entries or ce_entries to generate a record for.
Returns:
A string representing the Rock Ridge entry.
'''
outlist = []
if entries.sp_record is not None:
outlist.append(entries.sp_record.record())
if entries.rr_record is not None:
outlist.append(entries.rr_record.record())
for nm_record in entries.nm_records:
outlist.append(nm_record.record())
if entries.px_record is not None:
outlist.append(entries.px_record.record(self.rr_version))
for sl_record in entries.sl_records:
outlist.append(sl_record.record())
if entries.tf_record is not None:
outlist.append(entries.tf_record.record())
if entries.cl_record is not None:
outlist.append(entries.cl_record.record())
if entries.pl_record is not None:
outlist.append(entries.pl_record.record())
if entries.re_record is not None:
outlist.append(entries.re_record.record())
for es_record in entries.es_records:
outlist.append(es_record.record())
if entries.er_record is not None:
outlist.append(entries.er_record.record())
if entries.ce_record is not None:
outlist.append(entries.ce_record.record())
for pd_record in entries.pd_records:
outlist.append(pd_record.record())
if entries.st_record is not None:
outlist.append(entries.st_record.record())
if entries.sf_record is not None:
outlist.append(entries.sf_record.record())
return b''.join(outlist) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '18', '44', '50', '61', '72', '85', '89', '185']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n An internal method to add the appropriate name records to the ISO.\n Parameters:\n rr_name - The Rock Ridge name to add to the ISO.\n curr_dr_len - The current directory record length.\n Returns:\n The new directory record length.\n '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '17'], 'value': '-'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '-'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_DR_SIZE'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '25']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '<'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'rr_name'}, {'id': '25', 'type': 'block', 'children': ['26', '36']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_add_ce_record'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '43'], 'value': '-'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '-'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_DR_SIZE'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'RRNMRecord'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'new'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '58', 'type': 'slice', 'children': ['59', '60']}, {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '70']}, {'id': '63', 'type': 'attribute', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'dr_entries'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nm_records'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'augmented_assignment', 'children': ['74', '75'], 'value': '+='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'curr_dr_len'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'RRNMRecord'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '82', 'type': 'slice', 'children': ['83', '84']}, {'id': '83', 'type': 'colon', 'children': []}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'len_here'}, {'id': '89', 'type': 'while_statement', 'children': ['90', '96']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '<'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'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': 'rr_name'}; {'id': '96', 'type': 'block', 'children': ['97', '103', '118', '124', '138', '149', '181']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'set_continued'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '117']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '114', 'type': 'slice', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '116', 'type': 'colon', 'children': []}, {'id': '117', 'type': 'integer', 'children': [], 'value': '250'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'RRNMRecord'}, {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'new'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '132', 'type': 'slice', 'children': ['133', '134', '135']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '134', 'type': 'colon', 'children': []}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '147']}; {'id': '140', 'type': 'attribute', 'children': ['141', '146']}, {'id': '141', 'type': 'attribute', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ce_entries'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'nm_records'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'curr_nm'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '157']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '156'], 'value': 'is'}, {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'dr_entries'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ce_record'}; {'id': '156', 'type': 'None', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '167']}; {'id': '160', 'type': 'attribute', 'children': ['161', '166']}, {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'dr_entries'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ce_record'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'add_record'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'RRNMRecord'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'rr_name'}, {'id': '175', 'type': 'slice', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '177', 'type': 'colon', 'children': []}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '+'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'augmented_assignment', 'children': ['183', '184'], 'value': '+='}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '185', 'type': 'return_statement', 'children': ['186']} | def _add_name(self, rr_name, curr_dr_len):
'''
An internal method to add the appropriate name records to the ISO.
Parameters:
rr_name - The Rock Ridge name to add to the ISO.
curr_dr_len - The current directory record length.
Returns:
The new directory record length.
'''
len_here = ALLOWED_DR_SIZE - curr_dr_len - 5
if len_here < len(rr_name):
curr_dr_len = self._add_ce_record(curr_dr_len, 0)
len_here = ALLOWED_DR_SIZE - curr_dr_len - 5
curr_nm = RRNMRecord()
curr_nm.new(rr_name[:len_here])
self.dr_entries.nm_records.append(curr_nm)
curr_dr_len += RRNMRecord.length(rr_name[:len_here])
offset = len_here
while offset < len(rr_name):
curr_nm.set_continued()
length = min(len(rr_name[offset:]), 250)
curr_nm = RRNMRecord()
curr_nm.new(rr_name[offset:offset + length])
self.ce_entries.nm_records.append(curr_nm)
if self.dr_entries.ce_record is not None:
self.dr_entries.ce_record.add_record(RRNMRecord.length(rr_name[offset:offset + length]))
offset += length
return curr_dr_len |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_entry'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '14', '156', '175']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Add a new entry to this Rock Ridge Continuation Block. This method\n attempts to find a gap that fits the new length anywhere within this\n Continuation Block. If successful, it returns the offset at which\n it placed this entry. If unsuccessful, it returns None.\n Parameters:\n length - The length of the entry to find a gap for.\n Returns:\n The offset the entry was placed at, or None if no gap was found.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '12', 'type': 'unary_operator', 'children': ['13'], 'value': '-'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '24', '94']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_entries'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '48']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '42']}, {'id': '31', 'type': 'boolean_operator', 'children': ['32', '37'], 'value': 'and'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': '!='}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '<='}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '42', 'type': 'block', 'children': ['43', '47']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '47', 'type': 'break_statement', 'children': []}; {'id': '48', 'type': 'else_clause', 'children': ['49']}, {'id': '49', 'type': 'block', 'children': ['50', '60', '72', '82']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'lastentry'}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_entries'}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'lastend'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '71'], 'value': '-'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '68'], 'value': '+'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lastentry'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'lastentry'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'gapsize'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '81'], 'value': '-'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '80'], 'value': '-'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'lastend'}, {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '>='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'gapsize'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '86', 'type': 'block', 'children': ['87', '93']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'lastend'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'break_statement', 'children': []}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '100', '143']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_entries'}; {'id': '100', 'type': 'block', 'children': ['101', '110', '122', '132']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'lastentry'}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_entries'}; {'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'lastend'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '121'], 'value': '-'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '+'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'lastentry'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'lastentry'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '131'], 'value': '-'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '130'], 'value': '-'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_max_block_size'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'lastend'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '>='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '+'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'lastend'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'if_statement', 'children': ['146', '151']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '>='}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_max_block_size'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '>='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'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': 'bisect'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'insort_left'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': '_entries'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'RockRidgeContinuationEntry'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '175', 'type': 'return_statement', 'children': ['176']} | def add_entry(self, length):
'''
Add a new entry to this Rock Ridge Continuation Block. This method
attempts to find a gap that fits the new length anywhere within this
Continuation Block. If successful, it returns the offset at which
it placed this entry. If unsuccessful, it returns None.
Parameters:
length - The length of the entry to find a gap for.
Returns:
The offset the entry was placed at, or None if no gap was found.
'''
offset = -1
for index, entry in enumerate(self._entries):
if index == 0:
if entry.offset != 0 and length <= entry.offset:
offset = 0
break
else:
lastentry = self._entries[index - 1]
lastend = lastentry.offset + lastentry.length - 1
gapsize = entry.offset - lastend - 1
if gapsize >= length:
offset = lastend + 1
break
else:
if self._entries:
lastentry = self._entries[-1]
lastend = lastentry.offset + lastentry.length - 1
left = self._max_block_size - lastend - 1
if left >= length:
offset = lastend + 1
else:
if self._max_block_size >= length:
offset = 0
if offset >= 0:
bisect.insort_left(self._entries,
RockRidgeContinuationEntry(offset, length))
return offset |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'extent'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '22', '53', '65', '84', '97', '113', '144', '168']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Parse the passed in data into a UDF Descriptor tag.\n Parameters:\n data - The data to parse.\n extent - The extent to compare against for the tag location.\n Returns:\n Nothing.\n '''"}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_initialized'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'raise_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'UDF Tag already initialized'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '43']}; {'id': '24', 'type': 'tuple_pattern', 'children': ['25', '28', '31', '32', '33', '36', '37', '40']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'desc_version'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tag_checksum'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'reserved'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tag_serial_number'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'desc_crc'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'desc_crc_length'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag_location'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '51', '52']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'FMT'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '!='}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'reserved'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'raise_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Reserved data not 0!'"}, {'id': '65', 'type': 'if_statement', 'children': ['66', '76']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '75'], 'value': '!='}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_compute_csum'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '72', 'type': 'slice', 'children': ['73', '74']}, {'id': '73', 'type': 'colon', 'children': []}; {'id': '74', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tag_checksum'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'raise_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'Tag checksum does not match!'"}; {'id': '84', 'type': 'if_statement', 'children': ['85', '90']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '!='}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag_location'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'tag_location'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'extent'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '105']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': 'not'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'desc_version'}; {'id': '102', 'type': 'tuple', 'children': ['103', '104']}, {'id': '103', 'type': 'integer', 'children': [], 'value': '2'}; {'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', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'Tag version not 2 or 3'"}, {'id': '113', 'type': 'if_statement', 'children': ['114', '125']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '122'], 'value': '<'}, {'id': '115', 'type': 'parenthesized_expression', 'children': ['116']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '-'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'desc_crc_length'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'raise_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'Not enough CRC bytes to compute (expected at least %d, got %d)'"}; {'id': '134', 'type': 'tuple', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'desc_crc_length'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '143'], 'value': '-'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '160']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '!='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'desc_crc'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'crc_ccitt'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '152', 'type': 'slice', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '154', 'type': 'colon', 'children': []}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'desc_crc_length'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'raise_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'string', 'children': [], 'value': "'Tag CRC does not match!'"}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '173', 'type': 'True', 'children': []} | def parse(self, data, extent):
'''
Parse the passed in data into a UDF Descriptor tag.
Parameters:
data - The data to parse.
extent - The extent to compare against for the tag location.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Tag already initialized')
(self.tag_ident, self.desc_version, tag_checksum, reserved,
self.tag_serial_number, desc_crc, self.desc_crc_length,
self.tag_location) = struct.unpack_from(self.FMT, data, 0)
if reserved != 0:
raise pycdlibexception.PyCdlibInvalidISO('Reserved data not 0!')
if _compute_csum(data[:16]) != tag_checksum:
raise pycdlibexception.PyCdlibInvalidISO('Tag checksum does not match!')
if self.tag_location != extent:
self.tag_location = extent
if self.desc_version not in (2, 3):
raise pycdlibexception.PyCdlibInvalidISO('Tag version not 2 or 3')
if (len(data) - 16) < self.desc_crc_length:
raise pycdlibexception.PyCdlibInternalError('Not enough CRC bytes to compute (expected at least %d, got %d)' % (self.desc_crc_length, len(data) - 16))
if desc_crc != crc_ccitt(data[16:16 + self.desc_crc_length]):
raise pycdlibexception.PyCdlibInvalidISO('Tag CRC does not match!')
self._initialized = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '21', '63', '71', '104', '122', '151', '171', '191', '211', '231', '251', '271']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Parse the passed in data into a UDF Timestamp.\n Parameters:\n data - The data to parse.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'UDF Timestamp already initialized'"}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '53']}, {'id': '23', 'type': 'tuple_pattern', 'children': ['24', '25', '26', '29', '32', '35', '38', '41', '44', '47', '50']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'tz'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'timetype'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'year'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'day'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'minute'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'centiseconds'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'hundreds_microseconds'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'microseconds'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '61', '62']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'FMT'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'timetype'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '>>'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'timetype'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '71', 'type': 'function_definition', 'children': ['72', '73', '76']}; {'id': '72', 'type': 'function_name', 'children': [], 'value': 'twos_comp'}, {'id': '73', 'type': 'parameters', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '76', 'type': 'block', 'children': ['77', '79', '102']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'''\n Compute the 2's complement of int value val\n '''"}, {'id': '79', 'type': 'if_statement', 'children': ['80', '92']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '91'], 'value': '!='}, {'id': '81', 'type': 'parenthesized_expression', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '&'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '84', 'type': 'parenthesized_expression', 'children': ['85']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '<<'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'parenthesized_expression', 'children': ['88']}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '-'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '-'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '98', 'type': 'parenthesized_expression', 'children': ['99']}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '<<'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'tz'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'twos_comp'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '121']}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '120'], 'value': '|'}, {'id': '113', 'type': 'parenthesized_expression', 'children': ['114']}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '119'], 'value': '<<'}, {'id': '115', 'type': 'parenthesized_expression', 'children': ['116']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '&'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'timetype'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0xf'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'tz'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '135']}, {'id': '123', 'type': 'boolean_operator', 'children': ['124', '130'], 'value': 'or'}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': '<'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '128', 'type': 'unary_operator', 'children': ['129'], 'value': '-'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1440'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '>'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1440'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '143']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '141'], 'value': '!='}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'tz'}, {'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '2047'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'raise_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'Invalid UDF timezone'"}, {'id': '151', 'type': 'if_statement', 'children': ['152', '163']}; {'id': '152', 'type': 'boolean_operator', 'children': ['153', '158'], 'value': 'or'}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': '<'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'year'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '>'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '9999'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'raise_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'Invalid UDF year'"}, {'id': '171', 'type': 'if_statement', 'children': ['172', '183']}; {'id': '172', 'type': 'boolean_operator', 'children': ['173', '178'], 'value': 'or'}, {'id': '173', 'type': 'comparison_operator', 'children': ['174', '177'], 'value': '<'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '182'], 'value': '>'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'raise_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'Invalid UDF month'"}, {'id': '191', 'type': 'if_statement', 'children': ['192', '203']}; {'id': '192', 'type': 'boolean_operator', 'children': ['193', '198'], 'value': 'or'}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '197'], 'value': '<'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'day'}, {'id': '197', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '202'], 'value': '>'}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '31'}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'raise_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'Invalid UDF day'"}, {'id': '211', 'type': 'if_statement', 'children': ['212', '223']}; {'id': '212', 'type': 'boolean_operator', 'children': ['213', '218'], 'value': 'or'}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '217'], 'value': '<'}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'hour'}, {'id': '217', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '222'], 'value': '>'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '23'}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'raise_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'Invalid UDF hour'"}, {'id': '231', 'type': 'if_statement', 'children': ['232', '243']}; {'id': '232', 'type': 'boolean_operator', 'children': ['233', '238'], 'value': 'or'}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '237'], 'value': '<'}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'minute'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '242'], 'value': '>'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'minute'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '59'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'raise_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'Invalid UDF minute'"}, {'id': '251', 'type': 'if_statement', 'children': ['252', '263']}; {'id': '252', 'type': 'boolean_operator', 'children': ['253', '258'], 'value': 'or'}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '257'], 'value': '<'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '258', 'type': 'comparison_operator', 'children': ['259', '262'], 'value': '>'}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '59'}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'raise_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'string', 'children': [], 'value': "'Invalid UDF second'"}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': '_initialized'} | def parse(self, data):
'''
Parse the passed in data into a UDF Timestamp.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Timestamp already initialized')
(tz, timetype, self.year, self.month, self.day, self.hour, self.minute,
self.second, self.centiseconds, self.hundreds_microseconds,
self.microseconds) = struct.unpack_from(self.FMT, data, 0)
self.timetype = timetype >> 4
def twos_comp(val, bits):
'''
Compute the 2's complement of int value val
'''
if (val & (1 << (bits - 1))) != 0:
val = val - (1 << bits)
return val
self.tz = twos_comp(((timetype & 0xf) << 8) | tz, 12)
if self.tz < -1440 or self.tz > 1440:
if self.tz != -2047:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF timezone')
if self.year < 1 or self.year > 9999:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF year')
if self.month < 1 or self.month > 12:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF month')
if self.day < 1 or self.day > 31:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF day')
if self.hour < 0 or self.hour > 23:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF hour')
if self.minute < 0 or self.minute > 59:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF minute')
if self.second < 0 or self.second > 59:
raise pycdlibexception.PyCdlibInvalidISO('Invalid UDF second')
self._initialized = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '21', '45', '57', '69', '81', '93', '105', '117', '129', '141', '153', '165']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Parse the passed in data into a UDF Partition Header Descriptor.\n Parameters:\n data - The data to parse.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'UDF Partition Header Descriptor already initialized'"}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '35']}, {'id': '23', 'type': 'tuple_pattern', 'children': ['24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'unalloc_table_length'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unalloc_table_pos'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'unalloc_bitmap_length'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'unalloc_bitmap_pos'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'part_integrity_table_length'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'part_integrity_table_pos'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'freed_table_length'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'freed_table_pos'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'freed_bitmap_length'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'freed_bitmap_pos'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'reserved_unused'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43', '44']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'FMT'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '!='}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'unalloc_table_length'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'Partition Header unallocated table length not 0'"}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '!='}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'unalloc_table_pos'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'raise_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'Partition Header unallocated table position not 0'"}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '!='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'unalloc_bitmap_length'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'raise_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'Partition Header unallocated bitmap length not 0'"}, {'id': '81', 'type': 'if_statement', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '!='}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'unalloc_bitmap_pos'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'raise_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'Partition Header unallocated bitmap position not 0'"}, {'id': '93', 'type': 'if_statement', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '!='}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'part_integrity_table_length'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'raise_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'string', 'children': [], 'value': "'Partition Header partition integrity length not 0'"}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '!='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'part_integrity_table_pos'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'raise_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'Partition Header partition integrity position not 0'"}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '!='}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'freed_table_length'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'raise_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'Partition Header freed table length not 0'"}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '!='}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'freed_table_pos'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'raise_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Partition Header freed table position not 0'"}, {'id': '141', 'type': 'if_statement', 'children': ['142', '145']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '!='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'freed_bitmap_length'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'raise_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'Partition Header freed bitmap length not 0'"}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '!='}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'freed_bitmap_pos'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'raise_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'string', 'children': [], 'value': "'Partition Header freed bitmap position not 0'"}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': '_initialized'} | def parse(self, data):
'''
Parse the passed in data into a UDF Partition Header Descriptor.
Parameters:
data - The data to parse.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF Partition Header Descriptor already initialized')
(unalloc_table_length, unalloc_table_pos, unalloc_bitmap_length,
unalloc_bitmap_pos, part_integrity_table_length,
part_integrity_table_pos, freed_table_length, freed_table_pos,
freed_bitmap_length, freed_bitmap_pos,
reserved_unused) = struct.unpack_from(self.FMT, data, 0)
if unalloc_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated table length not 0')
if unalloc_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated table position not 0')
if unalloc_bitmap_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated bitmap length not 0')
if unalloc_bitmap_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header unallocated bitmap position not 0')
if part_integrity_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header partition integrity length not 0')
if part_integrity_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header partition integrity position not 0')
if freed_table_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed table length not 0')
if freed_table_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed table position not 0')
if freed_bitmap_length != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed bitmap length not 0')
if freed_bitmap_pos != 0:
raise pycdlibexception.PyCdlibInvalidISO('Partition Header freed bitmap position not 0')
self._initialized = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'finish_directory_parse'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '21']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n A method to finish up the parsing of this UDF File Entry directory.\n In particular, this method checks to see if it is in sorted order for\n future use.\n Parameters:\n None.\n Returns:\n Nothing.\n '''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '13']}, {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'UDF File Entry not initialized'"}, {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '28'], 'value': '!='}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'icb_tag'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'file_type'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'raise_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '35', 'type': 'argument_list', 'children': ['36']} | def finish_directory_parse(self):
'''
A method to finish up the parsing of this UDF File Entry directory.
In particular, this method checks to see if it is in sorted order for
future use.
Parameters:
None.
Returns:
Nothing.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF File Entry not initialized')
if self.icb_tag.file_type != 4:
raise pycdlibexception.PyCdlibInternalError('Can only finish_directory for a directory') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'valstr'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '21', '302']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n A method to parse an El Torito Boot Catalog out of a string.\n Parameters:\n valstr - The string to parse the El Torito Boot Catalog out of.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'El Torito Boot Catalog already initialized'"}, {'id': '21', 'type': 'if_statement', 'children': ['22', '29', '47', '73']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '=='}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'EXPECTING_VALIDATION_ENTRY'}, {'id': '29', 'type': 'block', 'children': ['30', '39']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'validation_entry'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'valstr'}, {'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': 'state'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'EXPECTING_INITIAL_ENTRY'}, {'id': '47', 'type': 'elif_clause', 'children': ['48', '55']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': '=='}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'EXPECTING_INITIAL_ENTRY'}, {'id': '55', 'type': 'block', 'children': ['56', '65']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'initial_entry'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'valstr'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'EXPECTING_SECTION_HEADER_OR_DONE'}, {'id': '73', 'type': 'else_clause', 'children': ['74']}; {'id': '74', 'type': 'block', 'children': ['75', '88']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'bytearray'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'list', 'children': ['85'], 'value': '[valstr[0]]'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'valstr'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92', '170', '199', '268', '293']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '91', 'type': 'string', 'children': [], 'value': "b'\\x00'"}; {'id': '92', 'type': 'block', 'children': ['93', '104', '164']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'last_section_index'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '103'], 'value': '-'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '108', '114']}, {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '114', 'type': 'block', 'children': ['115', '145']}, {'id': '115', 'type': 'if_statement', 'children': ['116', '126']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': '!='}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sec'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'num_section_entries'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sec'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'section_entries'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'El Torito section header specified %d entries, only saw %d'"}, {'id': '135', 'type': 'tuple', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'num_section_entries'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'section_entries'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '149']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'last_section_index'}, {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'if_statement', 'children': ['151', '156']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': '!='}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sec'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'header_indicator'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0x90'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'raise_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'string', 'children': [], 'value': "'Intermediate El Torito section header not properly specified'"}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '169', 'type': 'True', 'children': []}; {'id': '170', 'type': 'elif_clause', 'children': ['171', '176']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'in'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '173', 'type': 'tuple', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "b'\\x90'"}, {'id': '175', 'type': 'string', 'children': [], 'value': "b'\\x91'"}; {'id': '176', 'type': 'block', 'children': ['177', '183', '190']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'section_header'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'EltoritoSectionHeader'}; {'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': 'section_header'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'valstr'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'section_header'}, {'id': '199', 'type': 'elif_clause', 'children': ['200', '205']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'in'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '202', 'type': 'tuple', 'children': ['203', '204']}, {'id': '203', 'type': 'string', 'children': [], 'value': "b'\\x88'"}; {'id': '204', 'type': 'string', 'children': [], 'value': "b'\\x00'"}, {'id': '205', 'type': 'block', 'children': ['206', '212', '219']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'secentry'}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'EltoritoEntry'}, {'id': '211', 'type': 'argument_list', 'children': []}; {'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': 'secentry'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'valstr'}, {'id': '219', 'type': 'if_statement', 'children': ['220', '244', '257']}; {'id': '220', 'type': 'boolean_operator', 'children': ['221', '224'], 'value': 'and'}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '236'], 'value': '<'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'attribute', 'children': ['229', '235']}, {'id': '229', 'type': 'subscript', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '233', 'type': 'unary_operator', 'children': ['234'], 'value': '-'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'section_entries'}; {'id': '236', 'type': 'attribute', 'children': ['237', '243']}, {'id': '237', 'type': 'subscript', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '241', 'type': 'unary_operator', 'children': ['242'], 'value': '-'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'num_section_entries'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '255']}, {'id': '247', 'type': 'attribute', 'children': ['248', '254']}; {'id': '248', 'type': 'subscript', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '252', 'type': 'unary_operator', 'children': ['253'], 'value': '-'}, {'id': '253', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'add_parsed_entry'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'secentry'}, {'id': '257', 'type': 'else_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '266']}, {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'standalone_entries'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'secentry'}; {'id': '268', 'type': 'elif_clause', 'children': ['269', '272']}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': '=='}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '271', 'type': 'string', 'children': [], 'value': "b'\\x44'"}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'augmented_assignment', 'children': ['275', '288'], 'value': '+='}, {'id': '275', 'type': 'attribute', 'children': ['276', '287']}; {'id': '276', 'type': 'subscript', 'children': ['277', '285']}, {'id': '277', 'type': 'attribute', 'children': ['278', '284']}; {'id': '278', 'type': 'subscript', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '282', 'type': 'unary_operator', 'children': ['283'], 'value': '-'}, {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'section_entries'}, {'id': '285', 'type': 'unary_operator', 'children': ['286'], 'value': '-'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'selection_criteria'}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'valstr'}; {'id': '290', 'type': 'slice', 'children': ['291', '292']}, {'id': '291', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '292', 'type': 'colon', 'children': []}, {'id': '293', 'type': 'else_clause', 'children': ['294']}; {'id': '294', 'type': 'block', 'children': ['295']}, {'id': '295', 'type': 'raise_statement', 'children': ['296']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'string', 'children': [], 'value': "'Invalid El Torito Boot Catalog entry'"}; {'id': '302', 'type': 'return_statement', 'children': ['303']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': '_initialized'} | def parse(self, valstr):
'''
A method to parse an El Torito Boot Catalog out of a string.
Parameters:
valstr - The string to parse the El Torito Boot Catalog out of.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized')
if self.state == self.EXPECTING_VALIDATION_ENTRY:
self.validation_entry.parse(valstr)
self.state = self.EXPECTING_INITIAL_ENTRY
elif self.state == self.EXPECTING_INITIAL_ENTRY:
self.initial_entry.parse(valstr)
self.state = self.EXPECTING_SECTION_HEADER_OR_DONE
else:
val = bytes(bytearray([valstr[0]]))
if val == b'\x00':
last_section_index = len(self.sections) - 1
for index, sec in enumerate(self.sections):
if sec.num_section_entries != len(sec.section_entries):
raise pycdlibexception.PyCdlibInvalidISO('El Torito section header specified %d entries, only saw %d' % (sec.num_section_entries, len(sec.section_entries)))
if index != last_section_index:
if sec.header_indicator != 0x90:
raise pycdlibexception.PyCdlibInvalidISO('Intermediate El Torito section header not properly specified')
self._initialized = True
elif val in (b'\x90', b'\x91'):
section_header = EltoritoSectionHeader()
section_header.parse(valstr)
self.sections.append(section_header)
elif val in (b'\x88', b'\x00'):
secentry = EltoritoEntry()
secentry.parse(valstr)
if self.sections and len(self.sections[-1].section_entries) < self.sections[-1].num_section_entries:
self.sections[-1].add_parsed_entry(secentry)
else:
self.standalone_entries.append(secentry)
elif val == b'\x44':
self.sections[-1].section_entries[-1].selection_criteria += valstr[2:]
else:
raise pycdlibexception.PyCdlibInvalidISO('Invalid El Torito Boot Catalog entry')
return self._initialized |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_iso9660_filename'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fullname'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'interchange_level'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '19', '46', '60', '76', '106']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n A function to check that a file identifier conforms to the ISO9660 rules\n for a particular interchange level.\n Parameters:\n fullname - The name to check.\n interchange_level - The interchange level to check against.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '15']}, {'id': '11', 'type': 'tuple_pattern', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_split_iso9660_filename'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'fullname'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '38']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'and'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '!='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '23', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '24', 'type': 'parenthesized_expression', 'children': ['25']}, {'id': '25', 'type': 'boolean_operator', 'children': ['26', '32'], 'value': 'or'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '31'], 'value': '<'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], 'value': '>'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '32767'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'ISO9660 filenames must have a version between 1 and 32767'"}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52']}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '50'], 'value': 'and'}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'ISO9660 filenames must have a non-empty name or extension'"}; {'id': '60', 'type': 'if_statement', 'children': ['61', '68']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'or'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'}, {'id': '63', 'type': 'string', 'children': [], 'value': "b';'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'}; {'id': '66', 'type': 'string', 'children': [], 'value': "b';'"}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'raise_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'string', 'children': [], 'value': "'ISO9660 filenames must contain exactly one semicolon'"}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80', '103']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '=='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'interchange_level'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'if_statement', 'children': ['82', '95']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '89'], 'value': 'or'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '>'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '94'], 'value': '>'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'raise_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension'"}, {'id': '103', 'type': 'else_clause', 'children': ['104']}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'pass_statement', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '<'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'interchange_level'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '110', 'type': 'block', 'children': ['111', '116']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': '_check_d1_characters'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_check_d1_characters'}, {'id': '119', 'type': 'argument_list', 'children': ['120']} | def _check_iso9660_filename(fullname, interchange_level):
'''
A function to check that a file identifier conforms to the ISO9660 rules
for a particular interchange level.
Parameters:
fullname - The name to check.
interchange_level - The interchange level to check against.
Returns:
Nothing.
'''
(name, extension, version) = _split_iso9660_filename(fullname)
if version != b'' and (int(version) < 1 or int(version) > 32767):
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a version between 1 and 32767')
if not name and not extension:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a non-empty name or extension')
if b';' in name or b';' in extension:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must contain exactly one semicolon')
if interchange_level == 1:
if len(name) > 8 or len(extension) > 3:
raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension')
else:
pass
if interchange_level < 4:
_check_d1_characters(name)
_check_d1_characters(extension) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_yield_children'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '23', '27']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n An internal function to gather and yield all of the children of a Directory\n Record.\n Parameters:\n rec - The Directory Record to get all of the children from (must be a\n directory)\n Yields:\n Children of this Directory Record.\n Returns:\n Nothing.\n '''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '15']}, {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'Record is not a directory!'"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '26', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '32', 'type': 'block', 'children': ['33', '41', '47', '51', '128']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fi'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'file_identifier'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'fi'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'continue_statement', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'fi'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '83']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '74'], 'value': 'and'}, {'id': '53', 'type': 'boolean_operator', 'children': ['54', '67'], 'value': 'and'}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '60'], 'value': 'and'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': 'is'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'child_link_record_exists'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '73'], 'value': 'is'}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cl_to_moved_dr'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '82'], 'value': 'is'}, {'id': '75', 'type': 'attribute', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cl_to_moved_dr'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '82', 'type': 'None', 'children': []}, {'id': '83', 'type': 'block', 'children': ['84', '94']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cl_parent'}, {'id': '87', 'type': 'attribute', 'children': ['88', '93']}; {'id': '88', 'type': 'attribute', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cl_to_moved_dr'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '99']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cl_child'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cl_parent'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '122']}, {'id': '101', 'type': 'boolean_operator', 'children': ['102', '107'], 'value': 'and'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '106'], 'value': 'is'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cl_child'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '115'], 'value': '=='}; {'id': '108', 'type': 'call', 'children': ['109', '114']}, {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cl_child'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '114', 'type': 'argument_list', 'children': []}, {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123', '127']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cl_child'}, {'id': '127', 'type': 'break_statement', 'children': []}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'yield', 'children': ['130']} | def _yield_children(rec):
'''
An internal function to gather and yield all of the children of a Directory
Record.
Parameters:
rec - The Directory Record to get all of the children from (must be a
directory)
Yields:
Children of this Directory Record.
Returns:
Nothing.
'''
if not rec.is_dir():
raise pycdlibexception.PyCdlibInvalidInput('Record is not a directory!')
last = b''
for child in rec.children:
fi = child.file_identifier()
if fi == last:
continue
last = fi
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists() and child.rock_ridge.cl_to_moved_dr is not None and child.rock_ridge.cl_to_moved_dr.parent is not None:
cl_parent = child.rock_ridge.cl_to_moved_dr.parent
for cl_child in cl_parent.children:
if cl_child.rock_ridge is not None and cl_child.rock_ridge.name() == child.rock_ridge.name():
child = cl_child
break
yield child |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_dr_record_by_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '26', '34', '41', '50', '69', '73', '81', '243']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n An internal function to find an directory record on the ISO given an ISO\n or Joliet path. If the entry is found, it returns the directory record\n object corresponding to that entry. If the entry could not be found,\n a pycdlibexception.PyCdlibInvalidInput exception is raised.\n Parameters:\n vd - The Volume Descriptor to look in for the Directory Record.\n path - The ISO or Joliet entry to find the Directory Record for.\n encoding - The string encoding used for the path.\n Returns:\n The directory record entry representing the entry on the ISO.\n '''"}; {'id': '10', 'type': 'if_statement', 'children': ['11', '18']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'starts_with_slash'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'Must be a path starting with /'"}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'root_directory_record'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '37', 'type': 'string', 'children': [], 'value': "b'/'"}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'splitpath'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'split_path'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'currpath'}, {'id': '53', 'type': 'call', 'children': ['54', '67']}; {'id': '54', 'type': 'attribute', 'children': ['55', '66']}, {'id': '55', 'type': 'call', 'children': ['56', '64']}; {'id': '56', 'type': 'attribute', 'children': ['57', '63']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'splitpath'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tmpdr'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'dr'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'DirectoryRecord'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'while_statement', 'children': ['82', '83']}; {'id': '82', 'type': 'True', 'children': []}, {'id': '83', 'type': 'block', 'children': ['84', '88', '94', '98', '105', '144', '148', '170', '176', '205', '211', '220', '224']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'thelist'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'thelist'}, {'id': '105', 'type': 'while_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '<'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '109', 'type': 'block', 'children': ['110', '119', '125']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '118'], 'value': '//'}; {'id': '114', 'type': 'parenthesized_expression', 'children': ['115']}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'tmpdr'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'currpath'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '131', '138']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '<'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'thelist'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'tmpdr'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'else_clause', 'children': ['139']}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '163']}, {'id': '149', 'type': 'boolean_operator', 'children': ['150', '156'], 'value': 'and'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '!='}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '162'], 'value': '=='}, {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'currpath'}, {'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': 'child'}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'thelist'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'break_statement', 'children': []}; {'id': '176', 'type': 'if_statement', 'children': ['177', '190']}, {'id': '177', 'type': 'boolean_operator', 'children': ['178', '183'], 'value': 'and'}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '182'], 'value': 'is'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '182', 'type': 'None', 'children': []}, {'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': 'child'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'child_link_record_exists'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191', '199']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cl_to_moved_dr'}, {'id': '199', 'type': 'if_statement', 'children': ['200', '203']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'is'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '202', 'type': 'None', 'children': []}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'break_statement', 'children': []}, {'id': '205', 'type': 'if_statement', 'children': ['206', '208']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'splitpath'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'return_statement', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '211', 'type': 'if_statement', 'children': ['212', '218']}; {'id': '212', 'type': 'not_operator', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'is_dir'}, {'id': '217', 'type': 'argument_list', 'children': []}; {'id': '218', 'type': 'block', 'children': ['219']}, {'id': '219', 'type': 'break_statement', 'children': []}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'currpath'}, {'id': '227', 'type': 'call', 'children': ['228', '241']}; {'id': '228', 'type': 'attribute', 'children': ['229', '240']}, {'id': '229', 'type': 'call', 'children': ['230', '238']}; {'id': '230', 'type': 'attribute', 'children': ['231', '237']}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'splitpath'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '243', 'type': 'raise_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'string', 'children': [], 'value': "'Could not find path'"} | def _find_dr_record_by_name(vd, path, encoding):
'''
An internal function to find an directory record on the ISO given an ISO
or Joliet path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found,
a pycdlibexception.PyCdlibInvalidInput exception is raised.
Parameters:
vd - The Volume Descriptor to look in for the Directory Record.
path - The ISO or Joliet entry to find the Directory Record for.
encoding - The string encoding used for the path.
Returns:
The directory record entry representing the entry on the ISO.
'''
if not utils.starts_with_slash(path):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
root_dir_record = vd.root_directory_record()
if path == b'/':
return root_dir_record
splitpath = utils.split_path(path)
currpath = splitpath.pop(0).decode('utf-8').encode(encoding)
entry = root_dir_record
tmpdr = dr.DirectoryRecord()
while True:
child = None
thelist = entry.children
lo = 2
hi = len(thelist)
while lo < hi:
mid = (lo + hi) // 2
tmpdr.file_ident = currpath
if thelist[mid] < tmpdr:
lo = mid + 1
else:
hi = mid
index = lo
if index != len(thelist) and thelist[index].file_ident == currpath:
child = thelist[index]
if child is None:
break
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists():
child = child.rock_ridge.cl_to_moved_dr
if child is None:
break
if not splitpath:
return child
if not child.is_dir():
break
entry = child
currpath = splitpath.pop(0).decode('utf-8').encode(encoding)
raise pycdlibexception.PyCdlibInvalidInput('Could not find path') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_volume_descriptors'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '19', '311', '324', '334', '368']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n An internal method to parse the volume descriptors on an ISO.\n Parameters:\n None.\n Returns:\n Nothing.\n '''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_cdfp'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'seek'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '*'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '2048'}, {'id': '19', 'type': 'while_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '34', '45', '60', '73', '112']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}, {'id': '25', 'type': 'binary_operator', 'children': ['26', '33'], 'value': '//'}; {'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': '_cdfp'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'integer', 'children': [], 'value': '2048'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_cdfp'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'integer', 'children': [], 'value': '2048'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '52']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '51'], 'value': '!='}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '2048'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'Failed to read entire volume descriptor'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'tuple_pattern', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'desc_type'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'struct'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'unpack_from'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'=B5s'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '97']}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '90'], 'value': 'or'}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'not'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'desc_type'}, {'id': '77', 'type': 'tuple', 'children': ['78', '81', '84', '87']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'headervd'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_PRIMARY'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'headervd'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'not'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '92', 'type': 'tuple', 'children': ['93', '94', '95', '96']}, {'id': '93', 'type': 'string', 'children': [], 'value': "b'CD001'"}; {'id': '94', 'type': 'string', 'children': [], 'value': "b'BEA01'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "b'NSR02'"}; {'id': '96', 'type': 'string', 'children': [], 'value': "b'TEA01'"}, {'id': '97', 'type': 'block', 'children': ['98', '111']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_cdfp'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'seek'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '108']}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '2048'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'SEEK_CUR'}, {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'if_statement', 'children': ['113', '118', '147', '179', '276']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'desc_type'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_PRIMARY'}; {'id': '118', 'type': 'block', 'children': ['119', '130', '138']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'PrimaryOrSupplementaryVD'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_PRIMARY'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'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': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'pvds'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '147', 'type': 'elif_clause', 'children': ['148', '153']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'desc_type'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'headervd'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR'}, {'id': '153', 'type': 'block', 'children': ['154', '162', '170']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'vdst'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'headervd'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'VolumeDescriptorSetTerminator'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'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': 'vdst'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '177']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'vdsts'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'vdst'}, {'id': '179', 'type': 'elif_clause', 'children': ['180', '185']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'desc_type'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'headervd'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190', '216', '237', '252', '267']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '=='}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '189', 'type': 'string', 'children': [], 'value': "b'CD001'"}; {'id': '190', 'type': 'block', 'children': ['191', '199', '207']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'br'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'BootRecord'}; {'id': '198', 'type': 'argument_list', 'children': []}, {'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': 'br'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}, {'id': '207', 'type': 'expression_statement', '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': 'self'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'brs'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'br'}; {'id': '216', 'type': 'elif_clause', 'children': ['217', '220']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '=='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '219', 'type': 'string', 'children': [], 'value': "b'BEA01'"}; {'id': '220', 'type': 'block', 'children': ['221', '227']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': '_has_udf'}; {'id': '226', 'type': 'True', 'children': []}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '234']}, {'id': '229', 'type': 'attribute', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'udf_bea'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}, {'id': '237', 'type': 'elif_clause', 'children': ['238', '241']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': '=='}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '240', 'type': 'string', 'children': [], 'value': "b'NSR02'"}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'udf_nsr'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}; {'id': '252', 'type': 'elif_clause', 'children': ['253', '256']}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': '=='}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '255', 'type': 'string', 'children': [], 'value': "b'TEA01'"}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '264']}, {'id': '259', 'type': 'attribute', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'udf_tea'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}, {'id': '267', 'type': 'else_clause', 'children': ['268']}; {'id': '268', 'type': 'block', 'children': ['269']}, {'id': '269', 'type': 'raise_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'string', 'children': [], 'value': "'Invalid volume identification type'"}; {'id': '276', 'type': 'elif_clause', 'children': ['277', '282']}, {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '=='}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'desc_type'}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY'}; {'id': '282', 'type': 'block', 'children': ['283', '294', '302']}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'svd'}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'PrimaryOrSupplementaryVD'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'headervd'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'svd'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '299', 'type': 'argument_list', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'curr_extent'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'call', 'children': ['304', '309']}; {'id': '304', 'type': 'attribute', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'svds'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'svd'}, {'id': '311', 'type': 'if_statement', 'children': ['312', '316']}; {'id': '312', 'type': 'not_operator', 'children': ['313']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'pvds'}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'raise_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'string', 'children': [], 'value': "'Valid ISO9660 filesystems must have at least one PVD'"}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '329', 'type': 'subscript', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'pvds'}, {'id': '333', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '334', 'type': 'for_statement', 'children': ['335', '336', '343']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '336', 'type': 'subscript', 'children': ['337', '340']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'pvds'}; {'id': '340', 'type': 'slice', 'children': ['341', '342']}, {'id': '341', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '342', 'type': 'colon', 'children': []}, {'id': '343', 'type': 'block', 'children': ['344', '358']}; {'id': '344', 'type': 'if_statement', 'children': ['345', '350']}, {'id': '345', 'type': 'comparison_operator', 'children': ['346', '347'], 'value': '!='}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '350', 'type': 'block', 'children': ['351']}, {'id': '351', 'type': 'raise_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}, {'id': '357', 'type': 'string', 'children': [], 'value': "'Multiple occurrences of PVD did not agree!'"}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'assignment', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}, {'id': '363', 'type': 'attribute', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}; {'id': '368', 'type': 'if_statement', 'children': ['369', '373']}, {'id': '369', 'type': 'not_operator', 'children': ['370']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'vdsts'}, {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'raise_statement', 'children': ['375']}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '379', 'type': 'argument_list', 'children': ['380']} | def _parse_volume_descriptors(self):
'''
An internal method to parse the volume descriptors on an ISO.
Parameters:
None.
Returns:
Nothing.
'''
self._cdfp.seek(16 * 2048)
while True:
curr_extent = self._cdfp.tell() // 2048
vd = self._cdfp.read(2048)
if len(vd) != 2048:
raise pycdlibexception.PyCdlibInvalidISO('Failed to read entire volume descriptor')
(desc_type, ident) = struct.unpack_from('=B5s', vd, 0)
if desc_type not in (headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY,
headervd.VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR,
headervd.VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD,
headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY) or ident not in (b'CD001', b'BEA01', b'NSR02', b'TEA01'):
self._cdfp.seek(-2048, os.SEEK_CUR)
break
if desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY:
pvd = headervd.PrimaryOrSupplementaryVD(headervd.VOLUME_DESCRIPTOR_TYPE_PRIMARY)
pvd.parse(vd, curr_extent)
self.pvds.append(pvd)
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR:
vdst = headervd.VolumeDescriptorSetTerminator()
vdst.parse(vd, curr_extent)
self.vdsts.append(vdst)
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD:
if ident == b'CD001':
br = headervd.BootRecord()
br.parse(vd, curr_extent)
self.brs.append(br)
elif ident == b'BEA01':
self._has_udf = True
self.udf_bea.parse(vd, curr_extent)
elif ident == b'NSR02':
self.udf_nsr.parse(vd, curr_extent)
elif ident == b'TEA01':
self.udf_tea.parse(vd, curr_extent)
else:
raise pycdlibexception.PyCdlibInvalidISO('Invalid volume identification type')
elif desc_type == headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY:
svd = headervd.PrimaryOrSupplementaryVD(headervd.VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY)
svd.parse(vd, curr_extent)
self.svds.append(svd)
if not self.pvds:
raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one PVD')
self.pvd = self.pvds[0]
for pvd in self.pvds[1:]:
if pvd != self.pvd:
raise pycdlibexception.PyCdlibInvalidISO('Multiple occurrences of PVD did not agree!')
pvd.root_dir_record = self.pvd.root_dir_record
if not self.vdsts:
raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one Volume Descriptor Set Terminator') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_rr_record'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rr_path'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '25', '35', '42', '51', '70', '74', '268']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n An internal method to find an directory record on the ISO given a Rock\n Ridge path. If the entry is found, it returns the directory record\n object corresponding to that entry. If the entry could not be found, a\n pycdlibexception.PyCdlibInvalidInput is raised.\n Parameters:\n rr_path - The Rock Ridge path to lookup.\n Returns:\n The directory record entry representing the entry on the ISO.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'starts_with_slash'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'rr_path'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Must be a path starting with /'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'root_directory_record'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rr_path'}; {'id': '38', 'type': 'string', 'children': [], 'value': "b'/'"}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'splitpath'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'split_path'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rr_path'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'currpath'}; {'id': '54', 'type': 'call', 'children': ['55', '68']}, {'id': '55', 'type': 'attribute', 'children': ['56', '67']}; {'id': '56', 'type': 'call', 'children': ['57', '65']}, {'id': '57', 'type': 'attribute', 'children': ['58', '64']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'splitpath'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'root_dir_record'}; {'id': '74', 'type': 'while_statement', 'children': ['75', '76']}, {'id': '75', 'type': 'True', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77', '81', '87', '91', '98', '155', '159', '165', '195', '201', '230', '236', '245', '249']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'rr_children'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '98', 'type': 'while_statement', 'children': ['99', '102']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '<'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '102', 'type': 'block', 'children': ['103', '112', '118', '132']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '111'], 'value': '//'}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108']}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'thelist'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '124']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': 'is'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'raise_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'Record without Rock Ridge entry on Rock Ridge ISO'"}; {'id': '132', 'type': 'if_statement', 'children': ['133', '142', '149']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '141'], 'value': '<'}; {'id': '134', 'type': 'call', 'children': ['135', '140']}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'currpath'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '188']}; {'id': '166', 'type': 'boolean_operator', 'children': ['167', '179'], 'value': 'and'}, {'id': '167', 'type': 'boolean_operator', 'children': ['168', '174'], 'value': 'and'}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '!='}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': 'is'}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '187'], 'value': '=='}; {'id': '180', 'type': 'call', 'children': ['181', '186']}, {'id': '181', 'type': 'attribute', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'tmpchild'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '186', 'type': 'argument_list', 'children': []}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'currpath'}; {'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': 'child'}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'thelist'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '195', 'type': 'if_statement', 'children': ['196', '199']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'is'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '198', 'type': 'None', 'children': []}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'break_statement', 'children': []}, {'id': '201', 'type': 'if_statement', 'children': ['202', '215']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '208'], 'value': 'and'}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': 'is'}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '207', 'type': 'None', 'children': []}; {'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': 'child'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'child_link_record_exists'}; {'id': '214', 'type': 'argument_list', 'children': []}, {'id': '215', 'type': 'block', 'children': ['216', '224']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'cl_to_moved_dr'}; {'id': '224', 'type': 'if_statement', 'children': ['225', '228']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': 'is'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '227', 'type': 'None', 'children': []}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'break_statement', 'children': []}; {'id': '230', 'type': 'if_statement', 'children': ['231', '233']}, {'id': '231', 'type': 'not_operator', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'splitpath'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'return_statement', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '243']}, {'id': '237', 'type': 'not_operator', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '242', 'type': 'argument_list', 'children': []}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'break_statement', 'children': []}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'currpath'}; {'id': '252', 'type': 'call', 'children': ['253', '266']}, {'id': '253', 'type': 'attribute', 'children': ['254', '265']}; {'id': '254', 'type': 'call', 'children': ['255', '263']}, {'id': '255', 'type': 'attribute', 'children': ['256', '262']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'splitpath'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '268', 'type': 'raise_statement', 'children': ['269']}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '273', 'type': 'argument_list', 'children': ['274']} | def _find_rr_record(self, rr_path):
'''
An internal method to find an directory record on the ISO given a Rock
Ridge path. If the entry is found, it returns the directory record
object corresponding to that entry. If the entry could not be found, a
pycdlibexception.PyCdlibInvalidInput is raised.
Parameters:
rr_path - The Rock Ridge path to lookup.
Returns:
The directory record entry representing the entry on the ISO.
'''
if not utils.starts_with_slash(rr_path):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
root_dir_record = self.pvd.root_directory_record()
if rr_path == b'/':
return root_dir_record
splitpath = utils.split_path(rr_path)
currpath = splitpath.pop(0).decode('utf-8').encode('utf-8')
entry = root_dir_record
while True:
child = None
thelist = entry.rr_children
lo = 0
hi = len(thelist)
while lo < hi:
mid = (lo + hi) // 2
tmpchild = thelist[mid]
if tmpchild.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidInput('Record without Rock Ridge entry on Rock Ridge ISO')
if tmpchild.rock_ridge.name() < currpath:
lo = mid + 1
else:
hi = mid
index = lo
tmpchild = thelist[index]
if index != len(thelist) and tmpchild.rock_ridge is not None and tmpchild.rock_ridge.name() == currpath:
child = thelist[index]
if child is None:
break
if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists():
child = child.rock_ridge.cl_to_moved_dr
if child is None:
break
if not splitpath:
return child
if not child.is_dir():
break
entry = child
currpath = splitpath.pop(0).decode('utf-8').encode('utf-8')
raise pycdlibexception.PyCdlibInvalidInput('Could not find path') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_udf_descriptors'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '18', '35', '130', '153', '176', '189', '206', '210', '220', '228', '240', '254', '272', '276', '280', '288', '300', '314', '324', '334', '341', '354', '362', '374', '388', '403', '407', '415', '435', '449']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n An internal method to parse the UDF descriptors on the ISO. This should\n only be called if it the ISO has a valid UDF Volume Recognition Sequence\n at the beginning of the ISO.\n Parameters:\n None.\n Returns:\n Nothing.\n '''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'block_size'}, {'id': '11', 'type': 'call', 'children': ['12', '17']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'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': 'anchor_locations'}, {'id': '21', 'type': 'list', 'children': ['22', '29'], 'value': '[(256 * block_size, os.SEEK_SET), (-2048, os.SEEK_END)]'}; {'id': '22', 'type': 'tuple', 'children': ['23', '26']}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '*'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '256'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'SEEK_SET'}, {'id': '29', 'type': 'tuple', 'children': ['30', '32']}; {'id': '30', 'type': 'unary_operator', 'children': ['31'], 'value': '-'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '2048'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'SEEK_END'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '39', '40']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'whence'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'anchor_locations'}; {'id': '40', 'type': 'block', 'children': ['41', '51', '63', '74', '82', '90', '104', '112', '121']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '48']}, {'id': '43', 'type': 'attribute', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_cdfp'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'whence'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '62'], 'value': '//'}, {'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': '_cdfp'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tell'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'integer', 'children': [], 'value': '2048'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'anchor_data'}; {'id': '66', 'type': 'call', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_cdfp'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '2048'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'anchor_tag'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'anchor_tag'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'anchor_data'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '96']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '!='}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'anchor_tag'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'raise_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'UDF Anchor Tag identifier not 2'"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'anchor'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'UDFAnchorVolumeStructure'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'anchor_data'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'anchor_tag'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'udf_anchors'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_parse_udf_vol_descs'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '143', '150']}; {'id': '136', 'type': 'attribute', 'children': ['137', '142']}, {'id': '137', 'type': 'subscript', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'udf_anchors'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'main_vd_extent'}, {'id': '143', 'type': 'attribute', 'children': ['144', '149']}; {'id': '144', 'type': 'subscript', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'udf_anchors'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'main_vd_length'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_parse_udf_vol_descs'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '166', '173']}, {'id': '159', 'type': 'attribute', 'children': ['160', '165']}; {'id': '160', 'type': 'subscript', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'udf_anchors'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'reserve_vd_extent'}; {'id': '166', 'type': 'attribute', 'children': ['167', '172']}, {'id': '167', 'type': 'subscript', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'udf_anchors'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'reserve_vd_length'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'udf_reserve_descs'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': '_seek_to_extent'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'attribute', 'children': ['183', '188']}, {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'logical_volume'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'integrity_sequence_extent'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'integrity_data'}; {'id': '192', 'type': 'call', 'children': ['193', '198']}, {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_cdfp'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'attribute', 'children': ['200', '205']}; {'id': '200', 'type': 'attribute', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'logical_volume'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'integrity_sequence_length'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '213', 'type': 'attribute', 'children': ['214', '219']}; {'id': '214', 'type': 'attribute', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'logical_volume'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'integrity_sequence_extent'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}, {'id': '227', 'type': 'argument_list', 'children': []}; {'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': 'desc_tag'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '239']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'integrity_data'}; {'id': '236', 'type': 'slice', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '238', 'type': 'colon', 'children': []}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '240', 'type': 'if_statement', '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': 'desc_tag'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}, {'id': '245', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'raise_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'string', 'children': [], 'value': "'UDF Volume Integrity Tag identifier not 9'"}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '261']}; {'id': '256', 'type': 'attribute', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'udf_logical_volume_integrity'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '270', '271']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'integrity_data'}; {'id': '264', 'type': 'slice', 'children': ['265', '266', '267']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '266', 'type': 'colon', 'children': []}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '+'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '512'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'augmented_assignment', 'children': ['274', '275'], 'value': '+='}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'augmented_assignment', 'children': ['278', '279'], 'value': '+='}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}, {'id': '287', 'type': 'argument_list', 'children': []}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '299']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'integrity_data'}; {'id': '296', 'type': 'slice', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '298', 'type': 'colon', 'children': []}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '300', 'type': 'if_statement', 'children': ['301', '306']}, {'id': '301', 'type': 'comparison_operator', 'children': ['302', '305'], 'value': '!='}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '306', 'type': 'block', 'children': ['307']}, {'id': '307', 'type': 'raise_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'string', 'children': [], 'value': "'UDF Logical Volume Integrity Terminator Tag identifier not 8'"}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '321']}; {'id': '316', 'type': 'attribute', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'udf_logical_volume_integrity_terminator'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '327', 'type': 'attribute', 'children': ['328', '333']}; {'id': '328', 'type': 'attribute', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'partition'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'part_start_location'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': '_seek_to_extent'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'assignment', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'file_set_and_term_data'}; {'id': '344', 'type': 'call', 'children': ['345', '350']}, {'id': '345', 'type': 'attribute', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': '_cdfp'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'binary_operator', 'children': ['352', '353'], 'value': '*'}; {'id': '352', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}, {'id': '361', 'type': 'argument_list', 'children': []}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'call', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '367', 'type': 'argument_list', 'children': ['368', '373']}; {'id': '368', 'type': 'subscript', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'file_set_and_term_data'}; {'id': '370', 'type': 'slice', 'children': ['371', '372']}, {'id': '371', 'type': 'colon', 'children': []}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'block_size'}, {'id': '373', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '374', 'type': 'if_statement', 'children': ['375', '380']}, {'id': '375', 'type': 'comparison_operator', 'children': ['376', '379'], 'value': '!='}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}, {'id': '379', 'type': 'integer', 'children': [], 'value': '256'}; {'id': '380', 'type': 'block', 'children': ['381']}, {'id': '381', 'type': 'raise_statement', 'children': ['382']}; {'id': '382', 'type': 'call', 'children': ['383', '386']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '386', 'type': 'argument_list', 'children': ['387']}, {'id': '387', 'type': 'string', 'children': [], 'value': "'UDF File Set Tag identifier not 256'"}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'call', 'children': ['390', '395']}; {'id': '390', 'type': 'attribute', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'udf_file_set'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '395', 'type': 'argument_list', 'children': ['396', '401', '402']}; {'id': '396', 'type': 'subscript', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'file_set_and_term_data'}; {'id': '398', 'type': 'slice', 'children': ['399', '400']}, {'id': '399', 'type': 'colon', 'children': []}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'block_size'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'augmented_assignment', 'children': ['405', '406'], 'value': '+='}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '406', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'assignment', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '410', 'type': 'call', 'children': ['411', '414']}, {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'udfmod'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}; {'id': '414', 'type': 'argument_list', 'children': []}, {'id': '415', 'type': 'expression_statement', 'children': ['416']}; {'id': '416', 'type': 'call', 'children': ['417', '420']}, {'id': '417', 'type': 'attribute', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '420', 'type': 'argument_list', 'children': ['421', '426']}, {'id': '421', 'type': 'subscript', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'file_set_and_term_data'}, {'id': '423', 'type': 'slice', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'block_size'}, {'id': '425', 'type': 'colon', 'children': []}; {'id': '426', 'type': 'binary_operator', 'children': ['427', '428'], 'value': '-'}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '428', 'type': 'attribute', 'children': ['429', '434']}, {'id': '429', 'type': 'attribute', 'children': ['430', '433']}; {'id': '430', 'type': 'attribute', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'partition'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'part_start_location'}, {'id': '435', 'type': 'if_statement', 'children': ['436', '441']}; {'id': '436', 'type': 'comparison_operator', 'children': ['437', '440'], 'value': '!='}, {'id': '437', 'type': 'attribute', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}; {'id': '440', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '441', 'type': 'block', 'children': ['442']}; {'id': '442', 'type': 'raise_statement', 'children': ['443']}, {'id': '443', 'type': 'call', 'children': ['444', '447']}; {'id': '444', 'type': 'attribute', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}, {'id': '447', 'type': 'argument_list', 'children': ['448']}; {'id': '448', 'type': 'string', 'children': [], 'value': "'UDF File Set Terminator Tag identifier not 8'"}, {'id': '449', 'type': 'expression_statement', 'children': ['450']}; {'id': '450', 'type': 'call', 'children': ['451', '456']}, {'id': '451', 'type': 'attribute', 'children': ['452', '455']}; {'id': '452', 'type': 'attribute', 'children': ['453', '454']}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'udf_file_set_terminator'}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '456', 'type': 'argument_list', 'children': ['457', '458']}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'current_extent'} | def _parse_udf_descriptors(self):
'''
An internal method to parse the UDF descriptors on the ISO. This should
only be called if it the ISO has a valid UDF Volume Recognition Sequence
at the beginning of the ISO.
Parameters:
None.
Returns:
Nothing.
'''
block_size = self.pvd.logical_block_size()
anchor_locations = [(256 * block_size, os.SEEK_SET), (-2048, os.SEEK_END)]
for loc, whence in anchor_locations:
self._cdfp.seek(loc, whence)
extent = self._cdfp.tell() // 2048
anchor_data = self._cdfp.read(2048)
anchor_tag = udfmod.UDFTag()
anchor_tag.parse(anchor_data, extent)
if anchor_tag.tag_ident != 2:
raise pycdlibexception.PyCdlibInvalidISO('UDF Anchor Tag identifier not 2')
anchor = udfmod.UDFAnchorVolumeStructure()
anchor.parse(anchor_data, extent, anchor_tag)
self.udf_anchors.append(anchor)
self._parse_udf_vol_descs(self.udf_anchors[0].main_vd_extent,
self.udf_anchors[0].main_vd_length,
self.udf_main_descs)
self._parse_udf_vol_descs(self.udf_anchors[0].reserve_vd_extent,
self.udf_anchors[0].reserve_vd_length,
self.udf_reserve_descs)
self._seek_to_extent(self.udf_main_descs.logical_volume.integrity_sequence_extent)
integrity_data = self._cdfp.read(self.udf_main_descs.logical_volume.integrity_sequence_length)
offset = 0
current_extent = self.udf_main_descs.logical_volume.integrity_sequence_extent
desc_tag = udfmod.UDFTag()
desc_tag.parse(integrity_data[offset:], current_extent)
if desc_tag.tag_ident != 9:
raise pycdlibexception.PyCdlibInvalidISO('UDF Volume Integrity Tag identifier not 9')
self.udf_logical_volume_integrity.parse(integrity_data[offset:offset + 512], current_extent, desc_tag)
offset += block_size
current_extent += 1
desc_tag = udfmod.UDFTag()
desc_tag.parse(integrity_data[offset:], current_extent)
if desc_tag.tag_ident != 8:
raise pycdlibexception.PyCdlibInvalidISO('UDF Logical Volume Integrity Terminator Tag identifier not 8')
self.udf_logical_volume_integrity_terminator.parse(current_extent, desc_tag)
current_extent = self.udf_main_descs.partition.part_start_location
self._seek_to_extent(current_extent)
file_set_and_term_data = self._cdfp.read(2 * block_size)
desc_tag = udfmod.UDFTag()
desc_tag.parse(file_set_and_term_data[:block_size], 0)
if desc_tag.tag_ident != 256:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Tag identifier not 256')
self.udf_file_set.parse(file_set_and_term_data[:block_size],
current_extent, desc_tag)
current_extent += 1
desc_tag = udfmod.UDFTag()
desc_tag.parse(file_set_and_term_data[block_size:],
current_extent - self.udf_main_descs.partition.part_start_location)
if desc_tag.tag_ident != 8:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Terminator Tag identifier not 8')
self.udf_file_set_terminator.parse(current_extent, desc_tag) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_walk_udf_directories'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'extent_to_inode'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '19', '44', '54', '66']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n An internal method to walk a UDF filesystem and add all the metadata\n to this object.\n Parameters:\n extent_to_inode - A map from extent numbers to Inodes.\n Returns:\n Nothing.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'part_start'}; {'id': '12', 'type': 'attribute', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'udf_main_descs'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'partition'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'part_start_location'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'udf_root'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_parse_udf_file_entry'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '38', '43']}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '+'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'udf_file_set'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'root_dir_icb'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'log_block_num'}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'udf_file_set'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'root_dir_icb'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'udf_file_entries'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'deque'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'list', 'children': ['63'], 'value': '[self.udf_root]'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'udf_root'}; {'id': '66', 'type': 'while_statement', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'udf_file_entries'}; {'id': '68', 'type': 'block', 'children': ['69', '77', '83']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'udf_file_entries'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'popleft'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'continue_statement', 'children': []}, {'id': '83', 'type': 'for_statement', 'children': ['84', '87', '90']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'desc_len'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'desc_pos'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'alloc_descs'}; {'id': '90', 'type': 'block', 'children': ['91', '97', '104', '115', '119', '415']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'abs_file_ident_extent'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'part_start'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'desc_pos'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_seek_to_extent'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'abs_file_ident_extent'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'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': '_cdfp'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'desc_len'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '119', 'type': 'while_statement', 'children': ['120', '126']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '<'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '126', 'type': 'block', 'children': ['127', '138', '146', '160', '174', '182', '198', '213', '223', '236', '243', '265', '271', '277']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '137'], 'value': '//'}, {'id': '131', 'type': 'parenthesized_expression', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '+'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '*'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'abs_file_ident_extent'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'UDFTag'}, {'id': '145', 'type': 'argument_list', 'children': []}; {'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': 'desc_tag'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '157']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '154', 'type': 'slice', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '156', 'type': 'colon', 'children': []}, {'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '-'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'current_extent'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'part_start'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '166']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '165'], 'value': '!='}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tag_ident'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '257'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'raise_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'string', 'children': [], 'value': "'UDF File Identifier Tag identifier not 257'"}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'UDFFileIdentifierDescriptor'}, {'id': '181', 'type': 'argument_list', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '189', 'type': 'argument_list', 'children': ['190', '195', '196', '197']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '192', 'type': 'slice', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '194', 'type': 'colon', 'children': []}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'current_extent'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'desc_tag'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '204']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'is_parent'}, {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205', '212']}, {'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': 'udf_file_entry'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'track_file_ident_desc'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '212', 'type': 'continue_statement', 'children': []}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'abs_file_entry_extent'}; {'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '+'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'part_start'}; {'id': '218', 'type': 'attribute', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'icb'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'log_block_num'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'next_entry'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': '_parse_udf_file_entry'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232', '235']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'abs_file_entry_extent'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'icb'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'track_file_ident_desc'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '243', 'type': 'if_statement', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': 'is'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'next_entry'}; {'id': '246', 'type': 'None', 'children': []}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '254', '262']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'is_dir'}, {'id': '253', 'type': 'argument_list', 'children': []}; {'id': '254', 'type': 'block', 'children': ['255']}, {'id': '255', 'type': 'raise_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidISO'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'string', 'children': [], 'value': "'Empty UDF File Entry for directories are not allowed'"}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'continue_statement', 'children': []}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'file_entry'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '277', 'type': 'if_statement', 'children': ['278', '283', '291']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '282', 'type': 'argument_list', 'children': []}, {'id': '283', 'type': 'block', 'children': ['284']}; {'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': 'udf_file_entries'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '291', 'type': 'else_clause', 'children': ['292']}; {'id': '292', 'type': 'block', 'children': ['293', '320']}, {'id': '293', 'type': 'if_statement', 'children': ['294', '301', '314']}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '300'], 'value': '>'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'next_entry'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'get_data_length'}, {'id': '299', 'type': 'argument_list', 'children': []}; {'id': '300', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}, {'id': '305', 'type': 'binary_operator', 'children': ['306', '307'], 'value': '+'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'part_start'}, {'id': '307', 'type': 'subscript', 'children': ['308', '313']}; {'id': '308', 'type': 'subscript', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'alloc_descs'}; {'id': '312', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '314', 'type': 'else_clause', 'children': ['315']}, {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}, {'id': '319', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '320', 'type': 'if_statement', 'children': ['321', '336', '346']}, {'id': '321', 'type': 'boolean_operator', 'children': ['322', '327'], 'value': 'and'}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '326'], 'value': 'is'}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}; {'id': '326', 'type': 'None', 'children': []}, {'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': '=='}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}, {'id': '329', 'type': 'call', 'children': ['330', '335']}; {'id': '330', 'type': 'attribute', 'children': ['331', '334']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'extent_location'}, {'id': '335', 'type': 'argument_list', 'children': []}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '344']}, {'id': '339', 'type': 'attribute', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'add_dirrecord'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'next_entry'}; {'id': '346', 'type': 'else_clause', 'children': ['347']}, {'id': '347', 'type': 'block', 'children': ['348', '400', '409']}; {'id': '348', 'type': 'if_statement', 'children': ['349', '352', '359']}, {'id': '349', 'type': 'comparison_operator', 'children': ['350', '351'], 'value': 'in'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'extent_to_inode'}; {'id': '352', 'type': 'block', 'children': ['353']}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'ino'}; {'id': '356', 'type': 'subscript', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'extent_to_inode'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}, {'id': '359', 'type': 'else_clause', 'children': ['360']}; {'id': '360', 'type': 'block', 'children': ['361', '369', '385', '391']}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'ino'}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'Inode'}; {'id': '368', 'type': 'argument_list', 'children': []}, {'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': 'ino'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '374', 'type': 'argument_list', 'children': ['375', '376', '381', '384']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}; {'id': '376', 'type': 'call', 'children': ['377', '380']}, {'id': '377', 'type': 'attribute', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'get_data_length'}; {'id': '380', 'type': 'argument_list', 'children': []}, {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': '_cdfp'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'assignment', 'children': ['387', '390']}, {'id': '387', 'type': 'subscript', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'extent_to_inode'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'abs_file_data_extent'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'ino'}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'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': 'self'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'inodes'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '398', 'type': 'argument_list', 'children': ['399']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'ino'}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}, {'id': '401', 'type': 'call', 'children': ['402', '407']}; {'id': '402', 'type': 'attribute', 'children': ['403', '406']}, {'id': '403', 'type': 'attribute', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'ino'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'linked_records'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '407', 'type': 'argument_list', 'children': ['408']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '409', 'type': 'expression_statement', 'children': ['410']}; {'id': '410', 'type': 'assignment', 'children': ['411', '414']}, {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'next_entry'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'ino'}, {'id': '415', 'type': 'expression_statement', 'children': ['416']}; {'id': '416', 'type': 'call', 'children': ['417', '420']}, {'id': '417', 'type': 'attribute', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'finish_directory_parse'} | def _walk_udf_directories(self, extent_to_inode):
'''
An internal method to walk a UDF filesystem and add all the metadata
to this object.
Parameters:
extent_to_inode - A map from extent numbers to Inodes.
Returns:
Nothing.
'''
part_start = self.udf_main_descs.partition.part_start_location
self.udf_root = self._parse_udf_file_entry(part_start + self.udf_file_set.root_dir_icb.log_block_num,
self.udf_file_set.root_dir_icb,
None)
log_block_size = self.pvd.logical_block_size()
udf_file_entries = collections.deque([self.udf_root])
while udf_file_entries:
udf_file_entry = udf_file_entries.popleft()
if udf_file_entry is None:
continue
for desc_len, desc_pos in udf_file_entry.alloc_descs:
abs_file_ident_extent = part_start + desc_pos
self._seek_to_extent(abs_file_ident_extent)
data = self._cdfp.read(desc_len)
offset = 0
while offset < len(data):
current_extent = (abs_file_ident_extent * log_block_size + offset) // log_block_size
desc_tag = udfmod.UDFTag()
desc_tag.parse(data[offset:], current_extent - part_start)
if desc_tag.tag_ident != 257:
raise pycdlibexception.PyCdlibInvalidISO('UDF File Identifier Tag identifier not 257')
file_ident = udfmod.UDFFileIdentifierDescriptor()
offset += file_ident.parse(data[offset:],
current_extent,
desc_tag,
udf_file_entry)
if file_ident.is_parent():
udf_file_entry.track_file_ident_desc(file_ident)
continue
abs_file_entry_extent = part_start + file_ident.icb.log_block_num
next_entry = self._parse_udf_file_entry(abs_file_entry_extent,
file_ident.icb,
udf_file_entry)
udf_file_entry.track_file_ident_desc(file_ident)
if next_entry is None:
if file_ident.is_dir():
raise pycdlibexception.PyCdlibInvalidISO('Empty UDF File Entry for directories are not allowed')
else:
continue
file_ident.file_entry = next_entry
next_entry.file_ident = file_ident
if file_ident.is_dir():
udf_file_entries.append(next_entry)
else:
if next_entry.get_data_length() > 0:
abs_file_data_extent = part_start + next_entry.alloc_descs[0][1]
else:
abs_file_data_extent = 0
if self.eltorito_boot_catalog is not None and abs_file_data_extent == self.eltorito_boot_catalog.extent_location():
self.eltorito_boot_catalog.add_dirrecord(next_entry)
else:
if abs_file_data_extent in extent_to_inode:
ino = extent_to_inode[abs_file_data_extent]
else:
ino = inode.Inode()
ino.parse(abs_file_data_extent,
next_entry.get_data_length(), self._cdfp,
log_block_size)
extent_to_inode[abs_file_data_extent] = ino
self.inodes.append(ino)
ino.linked_records.append(next_entry)
next_entry.inode = ino
udf_file_entry.finish_directory_parse() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_write_directory_records'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '19', '23', '27', '41']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n An internal method to write out the directory records from a particular\n Volume Descriptor.\n Parameters:\n vd - The Volume Descriptor to write the Directory Records from.\n outfp - The file object to write data to.\n progress - The _Progress object to use for outputting progress.\n Returns:\n Nothing.\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'le_ptr_offset'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'be_ptr_offset'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'collections'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'deque'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'list', 'children': ['36'], 'value': '[vd.root_directory_record()]'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'root_directory_record'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'while_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dirs'}, {'id': '43', 'type': 'block', 'children': ['44', '52', '56', '164', '172']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'curr'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'popleft'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'curr_dirrecord_offset'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'curr'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'is_dir'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63', '77', '90', '100', '108', '115', '128', '138', '146', '153']}, {'id': '63', 'type': 'if_statement', 'children': ['64', '69']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': 'is'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'curr'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ptr'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'Directory has no Path Table Record'"}, {'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': 'outfp'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '89'], 'value': '+'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '*'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'path_table_location_le'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'le_ptr_offset'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'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': 'curr'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ptr'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'record_little_endian'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_outfp_write_with_check'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'augmented_assignment', 'children': ['110', '111'], 'value': '+='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'le_ptr_offset'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '127'], 'value': '+'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '*'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'vd'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'path_table_location_be'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'be_ptr_offset'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '131', 'type': 'call', 'children': ['132', '137']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'curr'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ptr'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'record_big_endian'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'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': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_outfp_write_with_check'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'be_ptr_offset'}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'progress'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'curr'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'get_data_length'}, {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dir_extent'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'curr'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'extent_location'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '177']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'curr'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '177', 'type': 'block', 'children': ['178', '186', '205', '216', '224', '231', '318']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'recstr'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '185', 'type': 'argument_list', 'children': []}; {'id': '186', 'type': 'if_statement', 'children': ['187', '196']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '195'], 'value': '>'}; {'id': '188', 'type': 'parenthesized_expression', 'children': ['189']}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'curr_dirrecord_offset'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'recstr'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}; {'id': '196', 'type': 'block', 'children': ['197', '201']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'augmented_assignment', 'children': ['199', '200'], 'value': '+='}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dir_extent'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'curr_dirrecord_offset'}; {'id': '204', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'outfp'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '215'], 'value': '+'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '*'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'dir_extent'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'log_block_size'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'curr_dirrecord_offset'}; {'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': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '_outfp_write_with_check'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'recstr'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'augmented_assignment', 'children': ['226', '227'], 'value': '+='}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'curr_dirrecord_offset'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'recstr'}, {'id': '231', 'type': 'if_statement', 'children': ['232', '237']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': 'is'}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '236', 'type': 'None', 'children': []}, {'id': '237', 'type': 'block', 'children': ['238', '308']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '248']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '247'], 'value': 'is'}; {'id': '240', 'type': 'attribute', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'dr_entries'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'ce_record'}, {'id': '247', 'type': 'None', 'children': []}; {'id': '248', 'type': 'block', 'children': ['249', '259', '280', '290', '298']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ce_rec'}; {'id': '252', 'type': 'attribute', 'children': ['253', '258']}, {'id': '253', 'type': 'attribute', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'dr_entries'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ce_record'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'binary_operator', 'children': ['266', '277'], 'value': '+'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '270'], 'value': '*'}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ce_rec'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'bl_cont_area'}; {'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': 'pvd'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '276', 'type': 'argument_list', 'children': []}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ce_rec'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'offset_cont_area'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'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': 'child'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'record_ce_entries'}, {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': '_outfp_write_with_check'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'outfp'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'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': 'progress'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'call'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '308', 'type': 'if_statement', 'children': ['309', '316']}, {'id': '309', 'type': 'call', 'children': ['310', '315']}; {'id': '310', 'type': 'attribute', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'child_link_record_exists'}, {'id': '315', 'type': 'argument_list', 'children': []}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'continue_statement', 'children': []}; {'id': '318', 'type': 'if_statement', 'children': ['319', '324']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'is_dir'}, {'id': '323', 'type': 'argument_list', 'children': []}; {'id': '324', 'type': 'block', 'children': ['325']}, {'id': '325', 'type': 'if_statement', 'children': ['326', '339']}; {'id': '326', 'type': 'boolean_operator', 'children': ['327', '333'], 'value': 'and'}, {'id': '327', 'type': 'not_operator', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'is_dot'}; {'id': '332', 'type': 'argument_list', 'children': []}, {'id': '333', 'type': 'not_operator', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'is_dotdot'}; {'id': '338', 'type': 'argument_list', 'children': []}, {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'call', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '345', 'type': 'argument_list', 'children': ['346']} | def _write_directory_records(self, vd, outfp, progress):
'''
An internal method to write out the directory records from a particular
Volume Descriptor.
Parameters:
vd - The Volume Descriptor to write the Directory Records from.
outfp - The file object to write data to.
progress - The _Progress object to use for outputting progress.
Returns:
Nothing.
'''
log_block_size = vd.logical_block_size()
le_ptr_offset = 0
be_ptr_offset = 0
dirs = collections.deque([vd.root_directory_record()])
while dirs:
curr = dirs.popleft()
curr_dirrecord_offset = 0
if curr.is_dir():
if curr.ptr is None:
raise pycdlibexception.PyCdlibInternalError('Directory has no Path Table Record')
outfp.seek(vd.path_table_location_le * log_block_size + le_ptr_offset)
ret = curr.ptr.record_little_endian()
self._outfp_write_with_check(outfp, ret)
le_ptr_offset += len(ret)
outfp.seek(vd.path_table_location_be * log_block_size + be_ptr_offset)
ret = curr.ptr.record_big_endian()
self._outfp_write_with_check(outfp, ret)
be_ptr_offset += len(ret)
progress.call(curr.get_data_length())
dir_extent = curr.extent_location()
for child in curr.children:
recstr = child.record()
if (curr_dirrecord_offset + len(recstr)) > log_block_size:
dir_extent += 1
curr_dirrecord_offset = 0
outfp.seek(dir_extent * log_block_size + curr_dirrecord_offset)
self._outfp_write_with_check(outfp, recstr)
curr_dirrecord_offset += len(recstr)
if child.rock_ridge is not None:
if child.rock_ridge.dr_entries.ce_record is not None:
ce_rec = child.rock_ridge.dr_entries.ce_record
outfp.seek(ce_rec.bl_cont_area * self.pvd.logical_block_size() + ce_rec.offset_cont_area)
rec = child.rock_ridge.record_ce_entries()
self._outfp_write_with_check(outfp, rec)
progress.call(len(rec))
if child.rock_ridge.child_link_record_exists():
continue
if child.is_dir():
if not child.is_dot() and not child.is_dotdot():
dirs.append(child) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_rm_dr_link'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '24', '28', '38', '42', '199']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n An internal method to remove a Directory Record link given the record.\n Parameters:\n rec - The Directory Record to remove.\n Returns:\n The number of bytes to remove from the ISO.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'is_file'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'raise_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'Cannot remove a directory with rm_hard_link (try rm_directory instead)'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'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': 'done'}, {'id': '41', 'type': 'False', 'children': []}; {'id': '42', 'type': 'while_statement', 'children': ['43', '45']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '45', 'type': 'block', 'children': ['46', '59', '180']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_remove_child_from_dr'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'index_in_parent'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '65']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': 'is'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '64', 'type': 'None', 'children': []}, {'id': '65', 'type': 'block', 'children': ['66', '70', '108', '116']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'for_statement', 'children': ['71', '74', '82', '99']}, {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'attribute', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'linked_records'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'if_statement', 'children': ['84', '93']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '89'], 'value': '=='}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '93', 'type': 'block', 'children': ['94', '98']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '98', 'type': 'break_statement', 'children': []}, {'id': '99', 'type': 'else_clause', 'children': ['100']}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'Could not find inode corresponding to record'"}; {'id': '108', 'type': 'delete_statement', 'children': ['109']}, {'id': '109', 'type': 'subscript', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'linked_records'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'found_index'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '123']}, {'id': '117', 'type': 'not_operator', 'children': ['118']}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'linked_records'}, {'id': '123', 'type': 'block', 'children': ['124', '128', '166', '172']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'for_statement', 'children': ['129', '132', '138', '157']}, {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ino'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'inodes'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'if_statement', 'children': ['140', '151']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '145'], 'value': '=='}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ino'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '151', 'type': 'block', 'children': ['152', '156']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '156', 'type': 'break_statement', 'children': []}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'raise_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'Could not find inode corresponding to record'"}; {'id': '166', 'type': 'delete_statement', 'children': ['167']}, {'id': '167', 'type': 'subscript', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'inodes'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'found_index'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'augmented_assignment', 'children': ['174', '175'], 'value': '+='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_data_length'}, {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'if_statement', 'children': ['181', '186', '193']}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '185'], 'value': 'is'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'data_continuation'}, {'id': '185', 'type': 'None', 'children': []}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'data_continuation'}, {'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': 'done'}; {'id': '198', 'type': 'True', 'children': []}, {'id': '199', 'type': 'return_statement', 'children': ['200']} | def _rm_dr_link(self, rec):
'''
An internal method to remove a Directory Record link given the record.
Parameters:
rec - The Directory Record to remove.
Returns:
The number of bytes to remove from the ISO.
'''
if not rec.is_file():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_hard_link (try rm_directory instead)')
num_bytes_to_remove = 0
logical_block_size = rec.vd.logical_block_size()
done = False
while not done:
num_bytes_to_remove += self._remove_child_from_dr(rec,
rec.index_in_parent,
logical_block_size)
if rec.inode is not None:
found_index = None
for index, link in enumerate(rec.inode.linked_records):
if id(link) == id(rec):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del rec.inode.linked_records[found_index]
if not rec.inode.linked_records:
found_index = None
for index, ino in enumerate(self.inodes):
if id(ino) == id(rec.inode):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del self.inodes[found_index]
num_bytes_to_remove += rec.get_data_length()
if rec.data_continuation is not None:
rec = rec.data_continuation
else:
done = True
return num_bytes_to_remove |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_rm_udf_link'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '31', '41', '45', '193', '207', '221']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n An internal method to remove a UDF File Entry link.\n Parameters:\n rec - The UDF File Entry to remove.\n Returns:\n The number of bytes to remove from the ISO.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '23']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '17'], 'value': 'and'}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'is_file'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_symlink'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Cannot remove a directory with rm_hard_link (try rm_directory instead)'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'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': 'pvd'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '51', '187']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'is'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52', '56', '94', '102', '110', '174']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'for_statement', 'children': ['57', '60', '68', '85']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'linked_records'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'if_statement', 'children': ['70', '79']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '75'], 'value': '=='}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '79', 'type': 'block', 'children': ['80', '84']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '84', 'type': 'break_statement', 'children': []}, {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'raise_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'Could not find inode corresponding to record'"}; {'id': '94', 'type': 'delete_statement', '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': 'rec'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'linked_records'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'found_index'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'augmented_assignment', 'children': ['104', '109'], 'value': '-='}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'num_udf'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '117']}, {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'linked_records'}, {'id': '117', 'type': 'block', 'children': ['118', '122', '160', '166']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'for_statement', 'children': ['123', '126', '132', '151']}, {'id': '123', 'type': 'pattern_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ino'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'inodes'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '145']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '139'], 'value': '=='}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ino'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '145', 'type': 'block', 'children': ['146', '150']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'found_index'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '150', 'type': 'break_statement', 'children': []}, {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'raise_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'string', 'children': [], 'value': "'Could not find inode corresponding to record'"}; {'id': '160', 'type': 'delete_statement', 'children': ['161']}, {'id': '161', 'type': 'subscript', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'inodes'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'found_index'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'augmented_assignment', 'children': ['168', '169'], 'value': '+='}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'get_data_length'}, {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'if_statement', 'children': ['175', '182']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '181'], 'value': '=='}; {'id': '176', 'type': 'attribute', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'num_udf'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '187', 'type': 'else_clause', 'children': ['188']}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '+='}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '193', 'type': 'if_statement', 'children': ['194', '199']}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '198'], 'value': 'is'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '198', 'type': 'None', 'children': []}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'raise_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'string', 'children': [], 'value': "'Cannot remove a UDF record with no parent'"}, {'id': '207', 'type': 'if_statement', 'children': ['208', '213']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': 'is'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '212', 'type': 'None', 'children': []}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'raise_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'Cannot remove a UDF record with no file identifier'"}, {'id': '221', 'type': 'return_statement', 'children': ['222']}; {'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '+'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': '_rm_udf_file_ident'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'file_ident'} | def _rm_udf_link(self, rec):
'''
An internal method to remove a UDF File Entry link.
Parameters:
rec - The UDF File Entry to remove.
Returns:
The number of bytes to remove from the ISO.
'''
if not rec.is_file() and not rec.is_symlink():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_hard_link (try rm_directory instead)')
logical_block_size = self.pvd.logical_block_size()
num_bytes_to_remove = 0
if rec.inode is not None:
found_index = None
for index, link in enumerate(rec.inode.linked_records):
if id(link) == id(rec):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del rec.inode.linked_records[found_index]
rec.inode.num_udf -= 1
if not rec.inode.linked_records:
found_index = None
for index, ino in enumerate(self.inodes):
if id(ino) == id(rec.inode):
found_index = index
break
else:
raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
del self.inodes[found_index]
num_bytes_to_remove += rec.get_data_length()
if rec.inode.num_udf == 0:
num_bytes_to_remove += logical_block_size
else:
num_bytes_to_remove += logical_block_size
if rec.parent is None:
raise pycdlibexception.PyCdlibInternalError('Cannot remove a UDF record with no parent')
if rec.file_ident is None:
raise pycdlibexception.PyCdlibInternalError('Cannot remove a UDF record with no file identifier')
return num_bytes_to_remove + self._rm_udf_file_ident(rec.parent, rec.file_ident.fi) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rm_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iso_path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'rr_name'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'joliet_path'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'udf_path'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '18', '31', '40', '56', '65', '80', '177', '181', '185', '189', '228', '318', '355']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'''\n Remove a file from the ISO.\n Parameters:\n iso_path - The path to the file to remove.\n rr_name - The Rock Ridge name of the file to remove.\n joliet_path - The Joliet path to the file to remove.\n udf_path - The UDF path to the file to remove.\n Returns:\n Nothing.\n '''"}; {'id': '18', 'type': 'if_statement', 'children': ['19', '23']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'This object is not yet initialized; call either open() or new() to create an ISO'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'iso_path_bytes'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'iso_path'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'starts_with_slash'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'iso_path_bytes'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'raise_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'Must be a path starting with /'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_find_iso_record'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'iso_path_bytes'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'is_file'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'raise_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'Cannot remove a directory with rm_file (try rm_directory instead)'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': 'is'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87', '116', '120', '135', '160']}, {'id': '87', 'type': 'if_statement', 'children': ['88', '108']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'list_comprehension', 'children': ['92', '101']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '=='}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dirrecords'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'raise_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"Cannot remove a file that is referenced by El Torito; either use \'rm_eltorito\' to remove El Torito first, or use \'rm_hard_link\' to hide the entry"'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'eltorito_entries'}, {'id': '119', 'type': 'dictionary', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '134']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'eltorito_entries'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'attribute', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'initial_entry'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '134', 'type': 'True', 'children': []}, {'id': '135', 'type': 'for_statement', 'children': ['136', '137', '142']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sec'}, {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'eltorito_boot_catalog'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '148']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'sec'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'section_entries'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '159']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'eltorito_entries'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '159', 'type': 'True', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '169']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '168'], 'value': 'in'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'inode'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'eltorito_entries'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'raise_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'string', 'children': [], 'value': '"Cannot remove a file that is referenced by El Torito; either use \'rm_eltorito\' to remove El Torito first, or use \'rm_hard_link\' to hide the entry"'}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}; {'id': '184', 'type': 'None', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '188', 'type': 'None', 'children': []}, {'id': '189', 'type': 'if_statement', 'children': ['190', '193']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'udf_path'}; {'id': '192', 'type': 'None', 'children': []}, {'id': '193', 'type': 'block', 'children': ['194', '208', '217']}; {'id': '194', 'type': 'if_statement', 'children': ['195', '200']}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '199'], 'value': 'is'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'udf_root'}, {'id': '199', 'type': 'None', 'children': []}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'raise_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'string', 'children': [], 'value': "'Can only specify a udf_path for a UDF ISO'"}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'udf_path_bytes'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'udf_path'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '222']}, {'id': '219', 'type': 'tuple_pattern', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': '_find_udf_record'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'udf_path_bytes'}; {'id': '228', 'type': 'if_statement', 'children': ['229', '234', '254']}, {'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': 'is'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '233', 'type': 'None', 'children': []}; {'id': '234', 'type': 'block', 'children': ['235']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'augmented_assignment', 'children': ['237', '238'], 'value': '+='}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': '_remove_child_from_dr'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244', '247']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'index_in_parent'}, {'id': '247', 'type': 'call', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'pvd'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}, {'id': '253', 'type': 'argument_list', 'children': []}; {'id': '254', 'type': 'else_clause', 'children': ['255']}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'while_statement', 'children': ['257', '262']}, {'id': '257', 'type': 'attribute', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'linked_records'}; {'id': '262', 'type': 'block', 'children': ['263', '273']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '266', 'type': 'subscript', 'children': ['267', '272']}, {'id': '267', 'type': 'attribute', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'inode'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'linked_records'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '273', 'type': 'if_statement', 'children': ['274', '281', '291', '309']}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'dr'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'DirectoryRecord'}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'augmented_assignment', 'children': ['284', '285'], 'value': '+='}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': '_rm_dr_link'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '291', 'type': 'elif_clause', 'children': ['292', '299']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '294', 'type': 'argument_list', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'udfmod'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'UDFFileEntry'}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'augmented_assignment', 'children': ['302', '303'], 'value': '+='}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}, {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': '_rm_udf_link'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '309', 'type': 'else_clause', 'children': ['310']}; {'id': '310', 'type': 'block', 'children': ['311']}, {'id': '311', 'type': 'raise_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInternalError'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'string', 'children': [], 'value': "'Saw a linked record that was neither ISO or UDF'"}; {'id': '318', 'type': 'if_statement', 'children': ['319', '332']}, {'id': '319', 'type': 'boolean_operator', 'children': ['320', '327'], 'value': 'and'}; {'id': '320', 'type': 'boolean_operator', 'children': ['321', '324'], 'value': 'and'}, {'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': 'is'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}, {'id': '323', 'type': 'None', 'children': []}; {'id': '324', 'type': 'comparison_operator', 'children': ['325', '326'], 'value': 'is'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'udf_file_entry'}; {'id': '326', 'type': 'None', 'children': []}, {'id': '327', 'type': 'comparison_operator', 'children': ['328', '331'], 'value': 'is'}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '331', 'type': 'None', 'children': []}; {'id': '332', 'type': 'block', 'children': ['333', '345']}, {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': '_rm_udf_file_ident'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'udf_file_ident'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'fi'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'augmented_assignment', 'children': ['347', '348'], 'value': '+='}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'}; {'id': '348', 'type': 'call', 'children': ['349', '354']}, {'id': '349', 'type': 'attribute', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'pvd'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'logical_block_size'}; {'id': '354', 'type': 'argument_list', 'children': []}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': '_finish_remove'}; {'id': '360', 'type': 'argument_list', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'num_bytes_to_remove'} | def rm_file(self, iso_path, rr_name=None, joliet_path=None, udf_path=None):
'''
Remove a file from the ISO.
Parameters:
iso_path - The path to the file to remove.
rr_name - The Rock Ridge name of the file to remove.
joliet_path - The Joliet path to the file to remove.
udf_path - The UDF path to the file to remove.
Returns:
Nothing.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
iso_path_bytes = utils.normpath(iso_path)
if not utils.starts_with_slash(iso_path_bytes):
raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /')
child = self._find_iso_record(iso_path_bytes)
if not child.is_file():
raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_file (try rm_directory instead)')
if self.eltorito_boot_catalog is not None:
if any([id(child) == id(rec) for rec in self.eltorito_boot_catalog.dirrecords]):
raise pycdlibexception.PyCdlibInvalidInput("Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry")
eltorito_entries = {}
eltorito_entries[id(self.eltorito_boot_catalog.initial_entry.inode)] = True
for sec in self.eltorito_boot_catalog.sections:
for entry in sec.section_entries:
eltorito_entries[id(entry.inode)] = True
if id(child.inode) in eltorito_entries:
raise pycdlibexception.PyCdlibInvalidInput("Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry")
num_bytes_to_remove = 0
udf_file_ident = None
udf_file_entry = None
if udf_path is not None:
if self.udf_root is None:
raise pycdlibexception.PyCdlibInvalidInput('Can only specify a udf_path for a UDF ISO')
udf_path_bytes = utils.normpath(udf_path)
(udf_file_ident, udf_file_entry) = self._find_udf_record(udf_path_bytes)
if child.inode is None:
num_bytes_to_remove += self._remove_child_from_dr(child,
child.index_in_parent,
self.pvd.logical_block_size())
else:
while child.inode.linked_records:
rec = child.inode.linked_records[0]
if isinstance(rec, dr.DirectoryRecord):
num_bytes_to_remove += self._rm_dr_link(rec)
elif isinstance(rec, udfmod.UDFFileEntry):
num_bytes_to_remove += self._rm_udf_link(rec)
else:
raise pycdlibexception.PyCdlibInternalError('Saw a linked record that was neither ISO or UDF')
if udf_file_ident is not None and udf_file_entry is None and udf_file_ident.parent is not None:
self._rm_udf_file_ident(udf_file_ident.parent, udf_file_ident.fi)
num_bytes_to_remove += self.pvd.logical_block_size()
self._finish_remove(num_bytes_to_remove, True) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_record'}, {'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', '10', '23', '27', '60', '72', '93', '114', '128']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Get the directory record for a particular path.\n Parameters:\n iso_path - The absolute path on the ISO9660 filesystem to get the\n record for.\n rr_path - The absolute path on the Rock Ridge filesystem to get the\n record for.\n joliet_path - The absolute path on the Joliet filesystem to get the\n record for.\n udf_path - The absolute path on the UDF filesystem to get the record\n for.\n Returns:\n An object that represents the path. This may be a dr.DirectoryRecord\n object (in the cases of iso_path, rr_path, or joliet_path), or a\n udf.UDFFileEntry object (in the case of udf_path).\n '''"}; {'id': '10', 'type': 'if_statement', 'children': ['11', '15']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_initialized'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'This object is not yet initialized; call either open() or new() to create an ISO'"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'num_paths'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'if_statement', 'children': ['32', '39', '51']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'list', 'children': ['35', '36', '37', '38'], 'value': "['joliet_path', 'rr_path', 'iso_path', 'udf_path']"}, {'id': '35', 'type': 'string', 'children': [], 'value': "'joliet_path'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'rr_path'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'iso_path'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'udf_path'"}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '46']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': 'is'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'augmented_assignment', 'children': ['49', '50'], 'value': '+='}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'num_paths'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Invalid keyword, must be one of \'iso_path\', \'rr_path\', \'joliet_path\', or \'udf_path\'"'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '!='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num_paths'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'string', 'children': [], 'value': '"Must specify one, and only one of \'iso_path\', \'rr_path\', \'joliet_path\', or \'udf_path\'"'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'joliet_path'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_get_entry'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_normalize_joliet_path'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'joliet_path'"}, {'id': '93', 'type': 'if_statement', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'rr_path'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'return_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': '_get_entry'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105', '113']}; {'id': '104', 'type': 'None', 'children': []}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'rr_path'"}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'in'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'udf_path'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '_get_udf_entry'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'udf_path'"}; {'id': '128', 'type': 'return_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': '_get_entry'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '142', '143']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'iso_path'"}; {'id': '142', 'type': 'None', 'children': []}, {'id': '143', 'type': 'None', 'children': []} | def get_record(self, **kwargs):
'''
Get the directory record for a particular path.
Parameters:
iso_path - The absolute path on the ISO9660 filesystem to get the
record for.
rr_path - The absolute path on the Rock Ridge filesystem to get the
record for.
joliet_path - The absolute path on the Joliet filesystem to get the
record for.
udf_path - The absolute path on the UDF filesystem to get the record
for.
Returns:
An object that represents the path. This may be a dr.DirectoryRecord
object (in the cases of iso_path, rr_path, or joliet_path), or a
udf.UDFFileEntry object (in the case of udf_path).
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
num_paths = 0
for key in kwargs:
if key in ['joliet_path', 'rr_path', 'iso_path', 'udf_path']:
if kwargs[key] is not None:
num_paths += 1
else:
raise pycdlibexception.PyCdlibInvalidInput("Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'")
if num_paths != 1:
raise pycdlibexception.PyCdlibInvalidInput("Must specify one, and only one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'")
if 'joliet_path' in kwargs:
return self._get_entry(None, None, self._normalize_joliet_path(kwargs['joliet_path']))
if 'rr_path' in kwargs:
return self._get_entry(None, utils.normpath(kwargs['rr_path']), None)
if 'udf_path' in kwargs:
return self._get_udf_entry(kwargs['udf_path'])
return self._get_entry(utils.normpath(kwargs['iso_path']), None, None) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'full_path_from_dirrecord'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'rockridge'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '12', '25', '29', '234', '250']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'''\n A method to get the absolute path of a directory record.\n Parameters:\n rec - The directory record to get the full path for.\n rockridge - Whether to get the rock ridge full path.\n Returns:\n A string representing the absolute path to the file on the ISO.\n '''"}; {'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': '_initialized'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'This object is not yet initialized; call either open() or new() to create an ISO'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '28', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '29', 'type': 'if_statement', 'children': ['30', '37', '157']}; {'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': 'rec'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dr'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'DirectoryRecord'}, {'id': '37', 'type': 'block', 'children': ['38', '42', '67', '76', '83', '99', '103']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '42', 'type': 'if_statement', 'children': ['43', '62']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '49'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'is'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'joliet_vd'}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '56'], 'value': '=='}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'vd'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'joliet_vd'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'utf-16_be'"}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'slash'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'is_root'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '83', 'type': 'if_statement', 'children': ['84', '91']}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'and'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'rockridge'}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': 'is'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'raise_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'pycdlibexception'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'PyCdlibInvalidInput'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'Cannot generate a Rock Ridge path on a non-Rock Ridge ISO'"}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '103', 'type': 'while_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'block', 'children': ['108', '151']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '113']}, {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'is_root'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '122', '137']}, {'id': '115', 'type': 'boolean_operator', 'children': ['116', '117'], 'value': 'and'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rockridge'}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': 'is'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}, {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '136'], 'value': '+'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'slash'}, {'id': '129', 'type': 'call', 'children': ['130', '135']}; {'id': '130', 'type': 'attribute', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'rock_ridge'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '137', 'type': 'else_clause', 'children': ['138']}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '150'], 'value': '+'}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'slash'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'file_identifier'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159', '168', '189', '198', '202']}, {'id': '159', 'type': 'if_statement', 'children': ['160', '165']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': 'is'}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '164', 'type': 'None', 'children': []}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '168', 'type': 'if_statement', 'children': ['169', '174', '183']}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '173'], 'value': 'is'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'file_ident'}, {'id': '173', 'type': 'None', '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': 'encoding'}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'file_ident'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '183', 'type': 'else_clause', 'children': ['184']}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'slash'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'udfparent'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '202', 'type': 'while_statement', 'children': ['203', '206']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'is'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'udfparent'}, {'id': '205', 'type': 'None', 'children': []}; {'id': '206', 'type': 'block', 'children': ['207', '215', '228']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'udfparent'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'file_identifier'}; {'id': '214', 'type': 'argument_list', 'children': []}, {'id': '215', 'type': 'if_statement', 'children': ['216', '219']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': '!='}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '218', 'type': 'string', 'children': [], 'value': "b'/'"}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '223', 'type': 'binary_operator', 'children': ['224', '227'], 'value': '+'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '+'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'slash'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'udfparent'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'udfparent'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '234', 'type': 'if_statement', 'children': ['235', '242']}, {'id': '235', 'type': 'comparison_operator', 'children': ['236', '239'], 'value': '>='}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'version_info'}, {'id': '239', 'type': 'tuple', 'children': ['240', '241']}; {'id': '240', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'block', 'children': ['243']}, {'id': '243', 'type': 'return_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '250', 'type': 'return_statement', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '260']}; {'id': '252', 'type': 'attribute', 'children': ['253', '259']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'string', 'children': [], 'value': "'utf-8'"} | def full_path_from_dirrecord(self, rec, rockridge=False):
'''
A method to get the absolute path of a directory record.
Parameters:
rec - The directory record to get the full path for.
rockridge - Whether to get the rock ridge full path.
Returns:
A string representing the absolute path to the file on the ISO.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO')
ret = b''
if isinstance(rec, dr.DirectoryRecord):
encoding = 'utf-8'
if self.joliet_vd is not None and id(rec.vd) == id(self.joliet_vd):
encoding = 'utf-16_be'
slash = '/'.encode(encoding)
if rec.is_root:
return '/'
if rockridge and rec.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidInput('Cannot generate a Rock Ridge path on a non-Rock Ridge ISO')
parent = rec
while parent is not None:
if not parent.is_root:
if rockridge and parent.rock_ridge is not None:
ret = slash + parent.rock_ridge.name() + ret
else:
ret = slash + parent.file_identifier() + ret
parent = parent.parent
else:
if rec.parent is None:
return '/'
if rec.file_ident is not None:
encoding = rec.file_ident.encoding
else:
encoding = 'utf-8'
slash = '/'.encode(encoding)
udfparent = rec
while udfparent is not None:
ident = udfparent.file_identifier()
if ident != b'/':
ret = slash + ident + ret
udfparent = udfparent.parent
if sys.version_info >= (3, 0):
return ret.decode(encoding)
return ret.decode(encoding).encode('utf-8') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_bird_conf_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '21', '31', '41', '52', '63', '97', '120', '150', '166', '208', '220', '235', '250', '260', '307', '327']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '24', 'type': 'subscript', 'children': ['25', '30']}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'config_file'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'variable_name'}; {'id': '34', 'type': 'subscript', 'children': ['35', '40']}, {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'variable_name'"}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'changes_counter'}; {'id': '44', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '45', 'type': 'subscript', 'children': ['46', '51']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'changes_counter'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '55', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '56', 'type': 'subscript', 'children': ['57', '62']}, {'id': '57', 'type': 'subscript', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'dummy_ip_prefix'"}, {'id': '63', 'type': 'try_statement', 'children': ['64', '72']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_ip_prefixes_from_bird'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '72', 'type': 'except_clause', 'children': ['73', '77']}, {'id': '73', 'type': 'as_pattern', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '75', 'type': 'as_pattern_target', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '77', 'type': 'block', 'children': ['78', '90']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '89']}; {'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"failed to open Bird configuration %s, this is a "'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"FATAL error, thus exiting main program"'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '100']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '100', 'type': 'block', 'children': ['101', '113']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '108']}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '112']}, {'id': '109', 'type': 'concatenated_string', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"found empty bird configuration %s, this is a FATAL"'}, {'id': '111', 'type': 'string', 'children': [], 'value': '" error, thus exiting main program"'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'not'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '124', 'type': 'block', 'children': ['125', '138', '146']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'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': 'log'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '137']}, {'id': '133', 'type': 'concatenated_string', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"dummy IP prefix %s wasn\'t found in bird "'}, {'id': '135', 'type': 'string', 'children': [], 'value': '"configuration, adding it. This shouldn\'t have "'}; {'id': '136', 'type': 'string', 'children': [], 'value': '"happened!"'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}; {'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': 'prefixes'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}, {'id': '149', 'type': 'True', 'children': []}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}, {'id': '153', 'type': 'call', 'children': ['154', '160']}; {'id': '154', 'type': 'attribute', 'children': ['155', '159']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'prefixes'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'subscript', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}; {'id': '168', 'type': 'block', 'children': ['169', '189', '204']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'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': 'log'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '183']}, {'id': '177', 'type': 'concatenated_string', 'children': ['178', '179', '180', '181', '182']}; {'id': '178', 'type': 'string', 'children': [], 'value': '"found %s IP prefixes in Bird configuration but "'}, {'id': '179', 'type': 'string', 'children': [], 'value': '"we aren\'t configured to run health checks on "'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"them. Either someone modified the configuration "'}, {'id': '181', 'type': 'string', 'children': [], 'value': '"manually or something went horrible wrong. We "'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"remove them from Bird configuration"'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'string', 'children': [], 'value': "','"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '195']}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'prefixes'}, {'id': '193', 'type': 'slice', 'children': ['194']}; {'id': '194', 'type': 'colon', 'children': []}, {'id': '195', 'type': 'generator_expression', 'children': ['196', '197', '200']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '200', 'type': 'if_clause', 'children': ['201']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'not'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}, {'id': '207', 'type': 'True', 'children': []}; {'id': '208', 'type': 'if_statement', 'children': ['209', '215']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'prefixes'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}, {'id': '219', 'type': 'True', 'children': []}; {'id': '220', 'type': 'if_statement', 'children': ['221', '223']}, {'id': '221', 'type': 'not_operator', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}, {'id': '223', 'type': 'block', 'children': ['224', '233']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '231']}; {'id': '226', 'type': 'attribute', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'no updates for bird configuration'"}, {'id': '233', 'type': 'return_statement', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'conf_updated'}, {'id': '235', 'type': 'if_statement', 'children': ['236', '243']}; {'id': '236', 'type': 'subscript', 'children': ['237', '242']}, {'id': '237', 'type': 'subscript', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'keep_changes'"}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'archive_bird_conf'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'changes_counter'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'tempname'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'write_temp_bird_conf'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258', '259']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'variable_name'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '260', 'type': 'try_statement', 'children': ['261', '270', '295']}, {'id': '261', 'type': 'block', 'children': ['262']}; {'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': 'rename'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'tempname'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '270', 'type': 'except_clause', 'children': ['271', '275']}, {'id': '271', 'type': 'as_pattern', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '273', 'type': 'as_pattern_target', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '275', 'type': 'block', 'children': ['276', '288']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '283']}; {'id': '278', 'type': 'attribute', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '283', 'type': 'argument_list', 'children': ['284', '287']}; {'id': '284', 'type': 'concatenated_string', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': '"failed to create Bird configuration %s, this "'}; {'id': '286', 'type': 'string', 'children': [], 'value': '"is a FATAL error, thus exiting main program"'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '295', 'type': 'else_clause', 'children': ['296']}; {'id': '296', 'type': 'block', 'children': ['297']}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '304']}, {'id': '299', 'type': 'attribute', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '306']}, {'id': '305', 'type': 'string', 'children': [], 'value': '"Bird configuration for IPv%s is updated"'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '307', 'type': 'if_statement', 'children': ['308', '314']}; {'id': '308', 'type': 'comparison_operator', 'children': ['309', '313'], 'value': '=='}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'prefixes'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '322']}, {'id': '317', 'type': 'attribute', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'concatenated_string', 'children': ['324', '325', '326']}; {'id': '324', 'type': 'string', 'children': [], 'value': '"Bird configuration doesn\'t have IP prefixes for "'}, {'id': '325', 'type': 'string', 'children': [], 'value': '"any of the services we monitor! It means local "'}; {'id': '326', 'type': 'string', 'children': [], 'value': '"node doesn\'t receive any traffic"'}, {'id': '327', 'type': 'return_statement', 'children': ['328']} | def _update_bird_conf_file(self, operation):
conf_updated = False
prefixes = []
ip_version = operation.ip_version
config_file = self.bird_configuration[ip_version]['config_file']
variable_name = self.bird_configuration[ip_version]['variable_name']
changes_counter =\
self.bird_configuration[ip_version]['changes_counter']
dummy_ip_prefix =\
self.bird_configuration[ip_version]['dummy_ip_prefix']
try:
prefixes = get_ip_prefixes_from_bird(config_file)
except OSError as error:
self.log.error("failed to open Bird configuration %s, this is a "
"FATAL error, thus exiting main program", error)
sys.exit(1)
if not prefixes:
self.log.error("found empty bird configuration %s, this is a FATAL"
" error, thus exiting main program", config_file)
sys.exit(1)
if dummy_ip_prefix not in prefixes:
self.log.warning("dummy IP prefix %s wasn't found in bird "
"configuration, adding it. This shouldn't have "
"happened!", dummy_ip_prefix)
prefixes.insert(0, dummy_ip_prefix)
conf_updated = True
ip_prefixes_without_check = set(prefixes).difference(
self.ip_prefixes[ip_version])
if ip_prefixes_without_check:
self.log.warning("found %s IP prefixes in Bird configuration but "
"we aren't configured to run health checks on "
"them. Either someone modified the configuration "
"manually or something went horrible wrong. We "
"remove them from Bird configuration",
','.join(ip_prefixes_without_check))
prefixes[:] = (ip for ip in prefixes
if ip not in ip_prefixes_without_check)
conf_updated = True
if operation.update(prefixes):
conf_updated = True
if not conf_updated:
self.log.info('no updates for bird configuration')
return conf_updated
if self.bird_configuration[ip_version]['keep_changes']:
archive_bird_conf(config_file, changes_counter)
tempname = write_temp_bird_conf(
dummy_ip_prefix,
config_file,
variable_name,
prefixes
)
try:
os.rename(tempname, config_file)
except OSError as error:
self.log.critical("failed to create Bird configuration %s, this "
"is a FATAL error, thus exiting main program",
error)
sys.exit(1)
else:
self.log.info("Bird configuration for IPv%s is updated",
ip_version)
if len(prefixes) == 1:
self.log.warning("Bird configuration doesn't have IP prefixes for "
"any of the services we monitor! It means local "
"node doesn't receive any traffic")
return conf_updated |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '137']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11', '21']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"no service checks are configured"'}, {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23', '38', '67']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '30']}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"going to lunch %s threads"'}; {'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': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '48', '61']}, {'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': 'config'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'has_option'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '47', 'type': 'string', 'children': [], 'value': "'splay_startup'"}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'splay_startup'}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'getfloat'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'splay_startup'"}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'splay_startup'}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '72']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '72', 'type': 'block', 'children': ['73', '83', '87', '119', '131']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"lunching thread for %s"'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_config'}; {'id': '86', 'type': 'dictionary', 'children': []}, {'id': '87', 'type': 'for_statement', 'children': ['88', '91', '96']}; {'id': '88', 'type': 'pattern_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'getter'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'SERVICE_OPTIONS_TYPE'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'try_statement', 'children': ['98', '115']}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_config'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '104', 'type': 'call', 'children': ['105', '112']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'getter'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '115', 'type': 'except_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'NoOptionError'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'pass_statement', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_thread'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ServiceCheck'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127', '130']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '_config'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'splay_startup'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_thread'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'while_statement', 'children': ['138', '139']}; {'id': '138', 'type': 'True', 'children': []}, {'id': '139', 'type': 'block', 'children': ['140', '153', '189', '207', '216', '224']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '143', 'type': 'call', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '152', 'type': 'True', 'children': []}, {'id': '153', 'type': 'if_statement', 'children': ['154', '159']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ServiceCheckDiedError'}, {'id': '159', 'type': 'block', 'children': ['160', '169', '182']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'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': 'log'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'critical'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'concatenated_string', 'children': ['178', '179', '180', '181']}; {'id': '178', 'type': 'string', 'children': [], 'value': '"This is a fatal error and the only way to "'}, {'id': '179', 'type': 'string', 'children': [], 'value': '"recover is to restart, thus exiting with a "'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"non-zero code and let systemd act by "'}, {'id': '181', 'type': 'string', 'children': [], 'value': '"triggering a restart"'}; {'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': 'sys'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '196']}, {'id': '191', 'type': 'attribute', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '200', '203', '206']}, {'id': '197', 'type': 'concatenated_string', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': '"returned an item from the queue for %s with IP "'}, {'id': '199', 'type': 'string', 'children': [], 'value': '"prefix %s and action to %s Bird configuration"'}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ip_prefix'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'bird_updated'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': '_update_bird_conf_file'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'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': 'self'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'task_done'}, {'id': '223', 'type': 'argument_list', 'children': []}; {'id': '224', 'type': 'if_statement', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'bird_updated'}; {'id': '226', 'type': 'block', 'children': ['227', '233']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '233', 'type': 'if_statement', 'children': ['234', '239', '251']}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '238'], 'value': 'is'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'bird_reconfigure_cmd'}; {'id': '238', 'type': 'None', 'children': []}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'reconfigure_bird'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'subscript', 'children': ['245', '250']}, {'id': '245', 'type': 'subscript', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'reconfigure_cmd'"}, {'id': '251', 'type': 'else_clause', 'children': ['252']}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'run_custom_bird_reconfigure'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'operation'} | def run(self):
if not self.services:
self.log.warning("no service checks are configured")
else:
self.log.info("going to lunch %s threads", len(self.services))
if self.config.has_option('daemon', 'splay_startup'):
splay_startup = self.config.getfloat('daemon', 'splay_startup')
else:
splay_startup = None
for service in self.services:
self.log.debug("lunching thread for %s", service)
_config = {}
for option, getter in SERVICE_OPTIONS_TYPE.items():
try:
_config[option] = getattr(self.config, getter)(service,
option)
except NoOptionError:
pass
_thread = ServiceCheck(service, _config, self.action,
splay_startup)
_thread.start()
while True:
operation = self.action.get(block=True)
if isinstance(operation, ServiceCheckDiedError):
self.log.critical(operation)
self.log.critical("This is a fatal error and the only way to "
"recover is to restart, thus exiting with a "
"non-zero code and let systemd act by "
"triggering a restart")
sys.exit(1)
self.log.info("returned an item from the queue for %s with IP "
"prefix %s and action to %s Bird configuration",
operation.name,
operation.ip_prefix,
operation)
bird_updated = self._update_bird_conf_file(operation)
self.action.task_done()
if bird_updated:
ip_version = operation.ip_version
if operation.bird_reconfigure_cmd is None:
reconfigure_bird(
self.bird_configuration[ip_version]['reconfigure_cmd'])
else:
run_custom_bird_reconfigure(operation) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'modify_ip_prefixes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'variable_name'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'reconfigure_cmd'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'keep_changes'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'changes_counter'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '12', 'type': 'block', 'children': ['13', '22', '30', '37', '41', '73', '80', '117', '145', '154', '161', '173', '238']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'PROGRAM_NAME'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'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': 'services'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'try_statement', 'children': ['42', '50']}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_ip_prefixes_from_bird'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '50', 'type': 'except_clause', 'children': ['51', '55']}, {'id': '51', 'type': 'as_pattern', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '53', 'type': 'as_pattern_target', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '55', 'type': 'block', 'children': ['56', '66']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '65']}; {'id': '62', 'type': 'concatenated_string', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"failed to open Bird configuration %s, this is a FATAL "'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"error, thus exiting main program"'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_name'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_variable_name_from_bird'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84', '97']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_name'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85', '93']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': '"failed to find variable name in %s, going to add it"'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}; {'id': '96', 'type': 'True', 'children': []}, {'id': '97', 'type': 'elif_clause', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '!='}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_name'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'variable_name'}, {'id': '101', 'type': 'block', 'children': ['102', '113']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '111', '112']}; {'id': '108', 'type': 'concatenated_string', 'children': ['109', '110']}, {'id': '109', 'type': 'string', 'children': [], 'value': '"found incorrect variable name in %s, going to add the "'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"correct one %s"'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_name'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'variable_name'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}; {'id': '116', 'type': 'True', 'children': []}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'not'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}, {'id': '121', 'type': 'block', 'children': ['122', '133', '141']}; {'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': 'log'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '131', '132']}; {'id': '128', 'type': 'concatenated_string', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': '"dummy IP prefix %s is missing from bird configuration "'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"%s, adding it"'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'config_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': 'ip_prefixes_in_bird'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}, {'id': '139', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}; {'id': '144', 'type': 'True', 'children': []}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_with_check'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_ip_prefixes_from_config'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152', '153']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_with_check'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}; {'id': '164', 'type': 'call', 'children': ['165', '171']}, {'id': '165', 'type': 'attribute', 'children': ['166', '170']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_with_check'}, {'id': '173', 'type': 'if_statement', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'if_statement', 'children': ['177', '184', '220']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'getboolean'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '183', 'type': 'string', 'children': [], 'value': "'purge_ip_prefixes'"}; {'id': '184', 'type': 'block', 'children': ['185', '201', '216']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194', '200']}, {'id': '191', 'type': 'concatenated_string', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': '"removing IP prefix(es) %s from %s because they don\'t "'}, {'id': '193', 'type': 'string', 'children': [], 'value': '"have a service check configured"'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "','"}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '207']}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}, {'id': '205', 'type': 'slice', 'children': ['206']}; {'id': '206', 'type': 'colon', 'children': []}, {'id': '207', 'type': 'generator_expression', 'children': ['208', '209', '212']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}; {'id': '212', 'type': 'if_clause', 'children': ['213']}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'not'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}, {'id': '219', 'type': 'True', 'children': []}; {'id': '220', 'type': 'else_clause', 'children': ['221']}, {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '231', '237']}; {'id': '228', 'type': 'concatenated_string', 'children': ['229', '230']}, {'id': '229', 'type': 'string', 'children': [], 'value': '"found IP prefixes %s in %s without a service "'}; {'id': '230', 'type': 'string', 'children': [], 'value': '"check configured"'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': "','"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_without_check'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '238', 'type': 'if_statement', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'update_bird_conf'}; {'id': '240', 'type': 'block', 'children': ['241', '250', '260']}, {'id': '241', 'type': 'if_statement', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'keep_changes'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'archive_bird_conf'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'changes_counter'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'tempname'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'write_temp_bird_conf'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258', '259']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'dummy_ip_prefix'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'variable_name'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'ip_prefixes_in_bird'}; {'id': '260', 'type': 'try_statement', 'children': ['261', '270', '304']}, {'id': '261', 'type': 'block', 'children': ['262']}; {'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': 'rename'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'tempname'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '270', 'type': 'except_clause', 'children': ['271', '275']}, {'id': '271', 'type': 'as_pattern', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '273', 'type': 'as_pattern_target', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '275', 'type': 'block', 'children': ['276', '290']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '279', 'type': 'parenthesized_expression', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '286']}, {'id': '281', 'type': 'attribute', 'children': ['282', '285']}; {'id': '282', 'type': 'concatenated_string', 'children': ['283', '284']}, {'id': '283', 'type': 'string', 'children': [], 'value': '"CRITICAL: failed to create Bird configuration {e}, "'}; {'id': '284', 'type': 'string', 'children': [], 'value': '"this is FATAL error, thus exiting main program"'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': '"{m}"'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '304', 'type': 'else_clause', 'children': ['305']}, {'id': '305', 'type': 'block', 'children': ['306', '314']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '311', 'type': 'argument_list', 'children': ['312', '313']}; {'id': '312', 'type': 'string', 'children': [], 'value': '"Bird configuration for IPv%s is updated"'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'reconfigure_bird'}, {'id': '317', 'type': 'argument_list', 'children': ['318']} | def modify_ip_prefixes(
config,
config_file,
variable_name,
dummy_ip_prefix,
reconfigure_cmd,
keep_changes,
changes_counter,
ip_version):
log = logging.getLogger(PROGRAM_NAME)
services = config.sections()
services.remove('daemon')
update_bird_conf = False
try:
ip_prefixes_in_bird = get_ip_prefixes_from_bird(config_file)
except OSError as error:
log.error("failed to open Bird configuration %s, this is a FATAL "
"error, thus exiting main program", error)
sys.exit(1)
_name = get_variable_name_from_bird(config_file)
if _name is None:
log.warning("failed to find variable name in %s, going to add it",
config_file)
update_bird_conf = True
elif _name != variable_name:
log.warning("found incorrect variable name in %s, going to add the "
"correct one %s", _name, variable_name)
update_bird_conf = True
if dummy_ip_prefix not in ip_prefixes_in_bird:
log.warning("dummy IP prefix %s is missing from bird configuration "
"%s, adding it", dummy_ip_prefix, config_file)
ip_prefixes_in_bird.insert(0, dummy_ip_prefix)
update_bird_conf = True
ip_prefixes_with_check = get_ip_prefixes_from_config(
config,
services,
ip_version)
ip_prefixes_with_check.add(dummy_ip_prefix)
ip_prefixes_without_check = set(ip_prefixes_in_bird).difference(
ip_prefixes_with_check)
if ip_prefixes_without_check:
if config.getboolean('daemon', 'purge_ip_prefixes'):
log.warning("removing IP prefix(es) %s from %s because they don't "
"have a service check configured",
','.join(ip_prefixes_without_check),
config_file)
ip_prefixes_in_bird[:] = (ip for ip in ip_prefixes_in_bird
if ip not in ip_prefixes_without_check)
update_bird_conf = True
else:
log.warning("found IP prefixes %s in %s without a service "
"check configured",
','.join(ip_prefixes_without_check),
config_file)
if update_bird_conf:
if keep_changes:
archive_bird_conf(config_file, changes_counter)
tempname = write_temp_bird_conf(
dummy_ip_prefix,
config_file,
variable_name,
ip_prefixes_in_bird
)
try:
os.rename(tempname, config_file)
except OSError as error:
msg = ("CRITICAL: failed to create Bird configuration {e}, "
"this is FATAL error, thus exiting main program"
.format(e=error))
sys.exit("{m}".format(m=msg))
else:
log.info("Bird configuration for IPv%s is updated", ip_version)
reconfigure_bird(reconfigure_cmd) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_configuration'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_dir'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'service_file'}, {'id': '7', 'type': 'block', 'children': ['8', '13', '21', '28', '53', '144', '166', '171', '178', '183']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'config_files'}, {'id': '11', 'type': 'list', 'children': ['12'], 'value': '[config_file]'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'configparser'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ConfigParser'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'read_dict'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_OPTIONS'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '38']}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'concatenated_string', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"{f} configuration file either isn\'t readable or "'}, {'id': '47', 'type': 'string', 'children': [], 'value': '"doesn\'t exist"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57', '92']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'service_file'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '68', '83']}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'service_file'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'raise_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'concatenated_string', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"{f} configuration file for a service check "'}, {'id': '77', 'type': 'string', 'children': [], 'value': '"doesn\'t exist"'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'service_file'}, {'id': '83', 'type': 'else_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'config_files'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'service_file'}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'config_dir'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '107', '122']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'config_dir'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'raise_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '118']}, {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'concatenated_string', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"{d} directory with configuration files for "'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"service checks doesn\'t exist"'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'config_dir'}; {'id': '122', 'type': 'else_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'config_files'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '134', 'type': 'argument_list', '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': 'os'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'config_dir'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'*.conf'"}; {'id': '144', 'type': 'try_statement', 'children': ['145', '153']}, {'id': '145', 'type': 'block', 'children': ['146']}; {'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': 'config'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'config_files'}, {'id': '153', 'type': 'except_clause', 'children': ['154', '160']}; {'id': '154', 'type': 'as_pattern', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'configparser'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '158', 'type': 'as_pattern_target', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'raise_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'configuration_check'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'build_bird_configuration'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'create_bird_config_files'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '183', 'type': 'return_statement', 'children': ['184']}; {'id': '184', 'type': 'expression_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'config'} | def load_configuration(config_file, config_dir, service_file):
config_files = [config_file]
config = configparser.ConfigParser()
config.read_dict(DEFAULT_OPTIONS)
if not os.path.isfile(config_file):
raise ValueError("{f} configuration file either isn't readable or "
"doesn't exist".format(f=config_file))
if service_file is not None:
if not os.path.isfile(service_file):
raise ValueError("{f} configuration file for a service check "
"doesn't exist".format(f=service_file))
else:
config_files.append(service_file)
elif config_dir is not None:
if not os.path.isdir(config_dir):
raise ValueError("{d} directory with configuration files for "
"service checks doesn't exist"
.format(d=config_dir))
else:
config_files.extend(glob.glob(os.path.join(config_dir, '*.conf')))
try:
config.read(config_files)
except configparser.Error as exc:
raise ValueError(exc)
configuration_check(config)
bird_configuration = build_bird_configuration(config)
create_bird_config_files(bird_configuration)
return config, bird_configuration |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'configuration_check'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '29', '39', '76', '94', '133', '212']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'log_level'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'loglevel'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'num_level'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23', '28']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pidfile'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'pidfile'"}, {'id': '39', 'type': 'if_statement', 'children': ['40', '56']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'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': 'dirname'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pidfile'}; {'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': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"{d} doesn\'t exit"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'}; {'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': 'identifier', 'children': [], 'value': 'pidfile'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '83']}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'num_level'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'raise_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'Invalid log level: {}'"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'log_level'}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '99']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '96', 'type': 'expression_list', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'log_file'"}; {'id': '98', 'type': 'string', 'children': [], 'value': "'stderr_file'"}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '108']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'has_option'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'try_statement', 'children': ['110', '122']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'touch'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '122', 'type': 'except_clause', 'children': ['123', '127']}, {'id': '123', 'type': 'as_pattern', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '125', 'type': 'as_pattern_target', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'raise_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '133', 'type': 'for_statement', 'children': ['134', '137', '142']}; {'id': '134', 'type': 'pattern_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'getter'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'DAEMON_OPTIONS_TYPE'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '141', 'type': 'argument_list', 'children': []}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'try_statement', 'children': ['144', '155', '173', '186']}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'getter'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '155', 'type': 'except_clause', 'children': ['156', '162']}; {'id': '156', 'type': 'as_pattern', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'configparser'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'NoOptionError'}; {'id': '160', 'type': 'as_pattern_target', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'not'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'DAEMON_OPTIONAL_OPTIONS'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'raise_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '173', 'type': 'except_clause', 'children': ['174', '180']}; {'id': '174', 'type': 'as_pattern', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'configparser'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '178', 'type': 'as_pattern_target', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '186', 'type': 'except_clause', 'children': ['187', '191']}, {'id': '187', 'type': 'as_pattern', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '189', 'type': 'as_pattern_target', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '191', 'type': 'block', 'children': ['192', '207']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '195', 'type': 'parenthesized_expression', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': '"invalid data for \'{opt}\' option in daemon section: {err}"'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '204']}, {'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'opt'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '207', 'type': 'raise_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'service_configuration_check'}, {'id': '215', 'type': 'argument_list', 'children': ['216']} | def configuration_check(config):
log_level = config.get('daemon', 'loglevel')
num_level = getattr(logging, log_level.upper(), None)
pidfile = config.get('daemon', 'pidfile')
if not os.path.isdir(os.path.dirname(pidfile)):
raise ValueError("{d} doesn't exit".format(d=os.path.dirname(pidfile)))
if not isinstance(num_level, int):
raise ValueError('Invalid log level: {}'.format(log_level))
for _file in 'log_file', 'stderr_file':
if config.has_option('daemon', _file):
try:
touch(config.get('daemon', _file))
except OSError as exc:
raise ValueError(exc)
for option, getter in DAEMON_OPTIONS_TYPE.items():
try:
getattr(config, getter)('daemon', option)
except configparser.NoOptionError as error:
if option not in DAEMON_OPTIONAL_OPTIONS:
raise ValueError(error)
except configparser.Error as error:
raise ValueError(error)
except ValueError as exc:
msg = ("invalid data for '{opt}' option in daemon section: {err}"
.format(opt=option, err=exc))
raise ValueError(msg)
service_configuration_check(config) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_bird_config_files'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '9']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ip_version'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}, {'id': '9', 'type': 'block', 'children': ['10', '18', '46']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '13', 'type': 'subscript', 'children': ['14', '17']}; {'id': '14', 'type': 'subscript', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'config_file'"}; {'id': '18', 'type': 'try_statement', 'children': ['19', '25']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'touch'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '25', 'type': 'except_clause', 'children': ['26', '30']}; {'id': '26', 'type': 'as_pattern', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '28', 'type': 'as_pattern_target', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"failed to create {f}:{e}"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52']}, {'id': '47', 'type': 'subscript', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bird_configuration'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ip_version'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'keep_changes'"}; {'id': '52', 'type': 'block', 'children': ['53', '72']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'history_dir'}; {'id': '56', 'type': 'call', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '71']}, {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'history'"}; {'id': '72', 'type': 'try_statement', 'children': ['73', '81', '85', '111']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'mkdir'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'history_dir'}, {'id': '81', 'type': 'except_clause', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'FileExistsError'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'pass_statement', 'children': []}, {'id': '85', 'type': 'except_clause', 'children': ['86', '90']}; {'id': '86', 'type': 'as_pattern', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '88', 'type': 'as_pattern_target', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'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': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'concatenated_string', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"failed to make directory {d} for keeping a "'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"history of changes for {b}:{e}"'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '105', '108']}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'history_dir'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'config_file'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': '"{d} is created"'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'} | def create_bird_config_files(bird_configuration):
for ip_version in bird_configuration:
config_file = bird_configuration[ip_version]['config_file']
try:
touch(config_file)
except OSError as exc:
raise ValueError("failed to create {f}:{e}"
.format(f=config_file, e=exc))
if bird_configuration[ip_version]['keep_changes']:
history_dir = os.path.join(os.path.dirname(config_file), 'history')
try:
os.mkdir(history_dir)
except FileExistsError:
pass
except OSError as exc:
raise ValueError("failed to make directory {d} for keeping a "
"history of changes for {b}:{e}"
.format(d=history_dir, b=config_file, e=exc))
else:
print("{d} is created".format(d=history_dir)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_logger'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '34', '41', '45', '59', '71', '100', '106', '118', '139', '215', '281', '341', '437']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'PROGRAM_NAME'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'num_level'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '33']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '22', 'type': 'call', 'children': ['23', '32']}, {'id': '23', 'type': 'attribute', 'children': ['24', '31']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'loglevel'"}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'setLevel'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'num_level'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '44', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'lengths'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '70'], 'value': '+'}, {'id': '63', 'type': 'subscript', 'children': ['64', '68']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'lengths'}; {'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'function_definition', 'children': ['72', '73', '74']}; {'id': '72', 'type': 'function_name', 'children': [], 'value': 'log_format'}, {'id': '73', 'type': 'parameters', 'children': []}; {'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': 'supported_keys'}; {'id': '78', 'type': 'list', 'children': ['79', '80', '81', '82', '83'], 'value': "[\n 'asctime',\n 'levelname',\n 'process',\n 'threadName',\n 'message',\n ]"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'asctime'"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'levelname'"}, {'id': '81', 'type': 'string', 'children': [], 'value': "'process'"}; {'id': '82', 'type': 'string', 'children': [], 'value': "'threadName'"}, {'id': '83', 'type': 'string', 'children': [], 'value': "'message'"}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '97']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'%({0:s})'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'supported_keys'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'custom_format'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'log_format'}, {'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': 'json_formatter'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'CustomJsonFormatter'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'custom_format'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'PROGRAM_NAME'}, {'id': '117', 'type': 'string', 'children': [], 'value': "': '"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'Formatter'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '132']}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'concatenated_string', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'%(asctime)s {program}[%(process)d] %(levelname)-8s '"}; {'id': '130', 'type': 'string', 'children': [], 'value': "'%(threadName)-{width}s %(message)s'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '136']}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'program'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'PROGRAM_NAME'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'width'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '147']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'has_option'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '146', 'type': 'string', 'children': [], 'value': "'log_file'"}, {'id': '147', 'type': 'block', 'children': ['148', '183', '208']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'file_handler'}, {'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': 'logging'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'RotatingFileHandler'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '165', '174']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '164', 'type': 'string', 'children': [], 'value': "'log_file'"}, {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'maxBytes'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'getint'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '173', 'type': 'string', 'children': [], 'value': "'log_maxbytes'"}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'backupCount'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'getint'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '182', 'type': 'string', 'children': [], 'value': "'log_backups'"}, {'id': '183', 'type': 'if_statement', 'children': ['184', '191', '199']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'getboolean'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '190', 'type': 'string', 'children': [], 'value': "'json_log_file'"}, {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'file_handler'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'json_formatter'}, {'id': '199', 'type': 'else_clause', 'children': ['200']}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'file_handler'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'addHandler'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'file_handler'}, {'id': '215', 'type': 'if_statement', 'children': ['216', '223']}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'has_option'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '222', 'type': 'string', 'children': [], 'value': "'log_server'"}, {'id': '223', 'type': 'block', 'children': ['224', '249', '274']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'udp_handler'}, {'id': '227', 'type': 'call', 'children': ['228', '233']}; {'id': '228', 'type': 'attribute', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'SysLogHandler'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'tuple', 'children': ['235', '242']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '241', 'type': 'string', 'children': [], 'value': "'log_server'"}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'getint'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '248', 'type': 'string', 'children': [], 'value': "'log_server_port'"}, {'id': '249', 'type': 'if_statement', 'children': ['250', '257', '265']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'getboolean'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '256', 'type': 'string', 'children': [], 'value': "'json_log_server'"}, {'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': 'udp_handler'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'json_formatter'}, {'id': '265', 'type': 'else_clause', 'children': ['266']}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'udp_handler'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'addHandler'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'udp_handler'}, {'id': '281', 'type': 'if_statement', 'children': ['282', '300']}; {'id': '282', 'type': 'parenthesized_expression', 'children': ['283']}, {'id': '283', 'type': 'boolean_operator', 'children': ['284', '292'], 'value': 'and'}; {'id': '284', 'type': 'not_operator', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'has_option'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '291', 'type': 'string', 'children': [], 'value': "'log_file'"}; {'id': '292', 'type': 'not_operator', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'has_option'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '299', 'type': 'string', 'children': [], 'value': "'log_server'"}; {'id': '300', 'type': 'block', 'children': ['301', '309', '334']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'stream_handler'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'StreamHandler'}; {'id': '308', 'type': 'argument_list', 'children': []}, {'id': '309', 'type': 'if_statement', 'children': ['310', '317', '325']}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'getboolean'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316']}, {'id': '315', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '316', 'type': 'string', 'children': [], 'value': "'json_stdout'"}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'stream_handler'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'json_formatter'}, {'id': '325', 'type': 'else_clause', 'children': ['326']}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'stream_handler'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'addHandler'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'stream_handler'}, {'id': '341', 'type': 'if_statement', 'children': ['342', '349', '385', '430']}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'has_option'}; {'id': '346', 'type': 'argument_list', 'children': ['347', '348']}, {'id': '347', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '348', 'type': 'string', 'children': [], 'value': "'stderr_file'"}, {'id': '349', 'type': 'block', 'children': ['350']}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'assignment', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'CustomRotatingFileLogger'}, {'id': '357', 'type': 'argument_list', 'children': ['358', '367', '376']}; {'id': '358', 'type': 'keyword_argument', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '364', 'type': 'argument_list', 'children': ['365', '366']}, {'id': '365', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '366', 'type': 'string', 'children': [], 'value': "'stderr_file'"}, {'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'maxbytes'}, {'id': '369', 'type': 'call', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'getint'}, {'id': '373', 'type': 'argument_list', 'children': ['374', '375']}; {'id': '374', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '375', 'type': 'string', 'children': [], 'value': "'log_maxbytes'"}; {'id': '376', 'type': 'keyword_argument', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'backupcount'}; {'id': '378', 'type': 'call', 'children': ['379', '382']}, {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'getint'}; {'id': '382', 'type': 'argument_list', 'children': ['383', '384']}, {'id': '383', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '384', 'type': 'string', 'children': [], 'value': "'log_backups'"}, {'id': '385', 'type': 'elif_clause', 'children': ['386', '403']}; {'id': '386', 'type': 'parenthesized_expression', 'children': ['387']}, {'id': '387', 'type': 'boolean_operator', 'children': ['388', '395'], 'value': 'and'}; {'id': '388', 'type': 'call', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'has_option'}; {'id': '392', 'type': 'argument_list', 'children': ['393', '394']}, {'id': '393', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '394', 'type': 'string', 'children': [], 'value': "'stderr_log_server'"}, {'id': '395', 'type': 'not_operator', 'children': ['396']}; {'id': '396', 'type': 'call', 'children': ['397', '400']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'has_option'}; {'id': '400', 'type': 'argument_list', 'children': ['401', '402']}, {'id': '401', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '402', 'type': 'string', 'children': [], 'value': "'stderr_file'"}, {'id': '403', 'type': 'block', 'children': ['404']}; {'id': '404', 'type': 'expression_statement', 'children': ['405']}, {'id': '405', 'type': 'assignment', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '409', 'type': 'call', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'CustomUdpLogger'}, {'id': '411', 'type': 'argument_list', 'children': ['412', '421']}; {'id': '412', 'type': 'keyword_argument', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'server'}; {'id': '414', 'type': 'call', 'children': ['415', '418']}, {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '418', 'type': 'argument_list', 'children': ['419', '420']}, {'id': '419', 'type': 'string', 'children': [], 'value': "'daemon'"}; {'id': '420', 'type': 'string', 'children': [], 'value': "'log_server'"}, {'id': '421', 'type': 'keyword_argument', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '423', 'type': 'call', 'children': ['424', '427']}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'getint'}, {'id': '427', 'type': 'argument_list', 'children': ['428', '429']}; {'id': '428', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '429', 'type': 'string', 'children': [], 'value': "'log_server_port'"}; {'id': '430', 'type': 'else_clause', 'children': ['431']}, {'id': '431', 'type': 'block', 'children': ['432']}; {'id': '432', 'type': 'expression_statement', 'children': ['433']}, {'id': '433', 'type': 'call', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '435', 'type': 'argument_list', 'children': ['436']}; {'id': '436', 'type': 'string', 'children': [], 'value': "'messages for unhandled exceptions will go to STDERR'"}, {'id': '437', 'type': 'return_statement', 'children': ['438']} | def setup_logger(config):
logger = logging.getLogger(PROGRAM_NAME)
num_level = getattr(
logging,
config.get('daemon', 'loglevel').upper(),
None
)
logger.setLevel(num_level)
lengths = []
for section in config:
lengths.append(len(section))
width = sorted(lengths)[-1] + 1
def log_format():
supported_keys = [
'asctime',
'levelname',
'process',
'threadName',
'message',
]
return ' '.join(['%({0:s})'.format(i) for i in supported_keys])
custom_format = log_format()
json_formatter = CustomJsonFormatter(custom_format,
prefix=PROGRAM_NAME + ': ')
formatter = logging.Formatter(
'%(asctime)s {program}[%(process)d] %(levelname)-8s '
'%(threadName)-{width}s %(message)s'
.format(program=PROGRAM_NAME, width=width)
)
if config.has_option('daemon', 'log_file'):
file_handler = logging.handlers.RotatingFileHandler(
config.get('daemon', 'log_file'),
maxBytes=config.getint('daemon', 'log_maxbytes'),
backupCount=config.getint('daemon', 'log_backups')
)
if config.getboolean('daemon', 'json_log_file'):
file_handler.setFormatter(json_formatter)
else:
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
if config.has_option('daemon', 'log_server'):
udp_handler = logging.handlers.SysLogHandler(
(
config.get('daemon', 'log_server'),
config.getint('daemon', 'log_server_port')
)
)
if config.getboolean('daemon', 'json_log_server'):
udp_handler.setFormatter(json_formatter)
else:
udp_handler.setFormatter(formatter)
logger.addHandler(udp_handler)
if (not config.has_option('daemon', 'log_file')
and not config.has_option('daemon', 'log_server')):
stream_handler = logging.StreamHandler()
if config.getboolean('daemon', 'json_stdout'):
stream_handler.setFormatter(json_formatter)
else:
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
if config.has_option('daemon', 'stderr_file'):
sys.stderr = CustomRotatingFileLogger(
filepath=config.get('daemon', 'stderr_file'),
maxbytes=config.getint('daemon', 'log_maxbytes'),
backupcount=config.getint('daemon', 'log_backups')
)
elif (config.has_option('daemon', 'stderr_log_server')
and not config.has_option('daemon', 'stderr_file')):
sys.stderr = CustomUdpLogger(
server=config.get('daemon', 'log_server'),
port=config.getint('daemon', 'log_server_port')
)
else:
print('messages for unhandled exceptions will go to STDERR')
return logger |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '12', '16', '20', '28', '33', '53', '60', '103', '126', '134', '141', '157', '165', '190', '206']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'arguments'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'docopt'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'/etc/anycast-healthchecker.conf'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'config_dir'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'/etc/anycast-healthchecker.d'"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'configparser'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ConfigParser'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'config_files'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': '[config_file]'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'config_file'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'config_files'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'config_dir'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'*.conf'"}, {'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': 'config'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'config_files'}; {'id': '60', 'type': 'try_statement', 'children': ['61', '69', '94']}, {'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': 'pid'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_processid'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '69', 'type': 'except_clause', 'children': ['70', '74']}; {'id': '70', 'type': 'as_pattern', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '72', 'type': 'as_pattern_target', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '74', 'type': 'block', 'children': ['75', '87']}, {'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': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"UNKNOWN: {e}"'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'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': 'sys'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'process_up'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'running'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '106']}; {'id': '104', 'type': 'not_operator', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'process_up'}; {'id': '106', 'type': 'block', 'children': ['107', '119']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': '"CRITICAL: anycast-healthchecker with pid ({p}) isn\'t running"'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '133', 'type': 'argument_list', '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': 'services'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'daemon'"}, {'id': '141', 'type': 'if_statement', 'children': ['142', '144']}; {'id': '142', 'type': 'not_operator', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '144', 'type': 'block', 'children': ['145', '150']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'string', 'children': [], 'value': '"UNKNOWN: No service checks are configured"'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'enabled_service_checks'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'parse_services'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '169', '182']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '=='}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'enabled_service_checks'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'block', 'children': ['170', '175']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'string', 'children': [], 'value': '"OK: Number of service checks is zero, no threads are running"'}, {'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': 'sys'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'configured_threads'}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '+'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'enabled_service_checks'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '193', 'type': 'list', 'children': ['194', '195', '196', '197', '198'], 'value': "['/bin/ps', 'h', '-T', '-p', '{n}'.format(n=pid)]"}; {'id': '194', 'type': 'string', 'children': [], 'value': "'/bin/ps'"}, {'id': '195', 'type': 'string', 'children': [], 'value': "'h'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "'-T'"}, {'id': '197', 'type': 'string', 'children': [], 'value': "'-p'"}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'{n}'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '206', 'type': 'try_statement', 'children': ['207', '240', '277', '304']}, {'id': '207', 'type': 'block', 'children': ['208', '228']}; {'id': '208', 'type': 'if_statement', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'arguments'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'-v'"}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'string', 'children': [], 'value': '"running {}"'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'check_output'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'except_clause', 'children': ['241', '247']}, {'id': '241', 'type': 'as_pattern', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'}, {'id': '245', 'type': 'as_pattern_target', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '247', 'type': 'block', 'children': ['248', '270']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"UNKNOWN: running \'{c}\' failed with return code: {r}"'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '265']}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'returncode'}; {'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': 'sys'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '277', 'type': 'except_clause', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'TimeoutExpired'}, {'id': '281', 'type': 'block', 'children': ['282', '297']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'string', 'children': [], 'value': '"UNKNOWN: running \'{}\' timed out"'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '304', 'type': 'else_clause', 'children': ['305']}, {'id': '305', 'type': 'block', 'children': ['306', '314', '328', '335']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'output_lines'}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'splitlines'}, {'id': '313', 'type': 'argument_list', 'children': []}; {'id': '314', 'type': 'if_statement', 'children': ['315', '318']}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'arguments'}, {'id': '317', 'type': 'string', 'children': [], 'value': "'-v'"}; {'id': '318', 'type': 'block', 'children': ['319']}, {'id': '319', 'type': 'for_statement', 'children': ['320', '321', '322']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'output_lines'}; {'id': '322', 'type': 'block', 'children': ['323']}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '326', 'type': 'argument_list', 'children': ['327']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'running_threads'}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'output_lines'}, {'id': '335', 'type': 'if_statement', 'children': ['336', '339', '364', '383']}; {'id': '336', 'type': 'comparison_operator', 'children': ['337', '338'], 'value': '=='}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'running_threads'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'configured_threads'}, {'id': '339', 'type': 'block', 'children': ['340', '357']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'call', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'string', 'children': [], 'value': '"OK: UP (pid={p}) and all threads ({t}) are running"'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '352']}, {'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '354', 'type': 'binary_operator', 'children': ['355', '356'], 'value': '-'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'configured_threads'}; {'id': '356', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'call', 'children': ['359', '362']}, {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}, {'id': '363', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '364', 'type': 'elif_clause', 'children': ['365', '370']}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '369'], 'value': '=='}; {'id': '366', 'type': 'binary_operator', 'children': ['367', '368'], 'value': '-'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'running_threads'}; {'id': '368', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '369', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '370', 'type': 'block', 'children': ['371', '376']}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'call', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '374', 'type': 'argument_list', 'children': ['375']}, {'id': '375', 'type': 'string', 'children': [], 'value': '"CRITICAL: No threads are running OpDocs ANYCAST-03"'}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'call', 'children': ['378', '381']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '383', 'type': 'else_clause', 'children': ['384']}; {'id': '384', 'type': 'block', 'children': ['385', '406']}, {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '388', 'type': 'argument_list', 'children': ['389']}, {'id': '389', 'type': 'call', 'children': ['390', '395']}; {'id': '390', 'type': 'attribute', 'children': ['391', '394']}, {'id': '391', 'type': 'concatenated_string', 'children': ['392', '393']}; {'id': '392', 'type': 'string', 'children': [], 'value': '"CRITICAL: Found {n} running threads while configured "'}, {'id': '393', 'type': 'string', 'children': [], 'value': '"number of threads is {c} OpDocs ANYCAST-03"'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '395', 'type': 'argument_list', 'children': ['396', '401']}; {'id': '396', 'type': 'keyword_argument', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '398', 'type': 'binary_operator', 'children': ['399', '400'], 'value': '-'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'running_threads'}; {'id': '400', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '401', 'type': 'keyword_argument', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '403', 'type': 'binary_operator', 'children': ['404', '405'], 'value': '-'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'configured_threads'}, {'id': '405', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '406', 'type': 'expression_statement', 'children': ['407']}, {'id': '407', 'type': 'call', 'children': ['408', '411']}; {'id': '408', 'type': 'attribute', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '411', 'type': 'argument_list', 'children': ['412']} | def main():
arguments = docopt(__doc__)
config_file = '/etc/anycast-healthchecker.conf'
config_dir = '/etc/anycast-healthchecker.d'
config = configparser.ConfigParser()
config_files = [config_file]
config_files.extend(glob.glob(os.path.join(config_dir, '*.conf')))
config.read(config_files)
try:
pid = get_processid(config)
except ValueError as exc:
print("UNKNOWN: {e}".format(e=exc))
sys.exit(3)
else:
process_up = running(pid)
if not process_up:
print("CRITICAL: anycast-healthchecker with pid ({p}) isn't running"
.format(p=pid))
sys.exit(3)
services = config.sections()
services.remove('daemon')
if not services:
print("UNKNOWN: No service checks are configured")
sys.exit(3)
enabled_service_checks = parse_services(config, services)
if enabled_service_checks == 0:
print("OK: Number of service checks is zero, no threads are running")
sys.exit(0)
else:
configured_threads = enabled_service_checks + 1
cmd = ['/bin/ps', 'h', '-T', '-p', '{n}'.format(n=pid)]
try:
if arguments['-v']:
print("running {}".format(' '.join(cmd)))
out = subprocess.check_output(cmd, timeout=1)
except subprocess.CalledProcessError as exc:
print("UNKNOWN: running '{c}' failed with return code: {r}"
.format(c=' '.join(cmd), r=exc.returncode))
sys.exit(3)
except subprocess.TimeoutExpired:
print("UNKNOWN: running '{}' timed out".format(' '.join(cmd)))
sys.exit(3)
else:
output_lines = out.splitlines()
if arguments['-v']:
for line in output_lines:
print(line)
running_threads = len(output_lines)
if running_threads == configured_threads:
print("OK: UP (pid={p}) and all threads ({t}) are running"
.format(p=pid, t=configured_threads - 1))
sys.exit(0)
elif running_threads - 1 == 0:
print("CRITICAL: No threads are running OpDocs ANYCAST-03")
sys.exit(2)
else:
print("CRITICAL: Found {n} running threads while configured "
"number of threads is {c} OpDocs ANYCAST-03"
.format(n=running_threads - 1, c=configured_threads - 1))
sys.exit(2) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ve_base'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '48', '146']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 've_base_value'}; {'id': '10', 'type': 'call', 'children': ['11', '20']}, {'id': '11', 'type': 'attribute', 'children': ['12', '19']}; {'id': '12', 'type': 'subscript', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'headings'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'default_heading'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'virtualenvs'"}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24', '36']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 've_base_value'}; {'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': 've_base'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 've_base_value'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 've_base'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'WORKON_HOME'"}, {'id': '47', 'type': 'string', 'children': [], 'value': "''"}; {'id': '48', 'type': 'if_statement', 'children': ['49', '51']}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 've_base'}, {'id': '51', 'type': 'block', 'children': ['52', '113', '128', '134']}; {'id': '52', 'type': 'if_statement', 'children': ['53', '66', '101']}, {'id': '53', 'type': 'boolean_operator', 'children': ['54', '61'], 'value': 'and'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '60'], 'value': '=='}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'system'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'string', 'children': [], 'value': "'Windows'"}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '65'], 'value': '=='}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'nt'"}; {'id': '66', 'type': 'block', 'children': ['67', '76', '86']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_win_drive'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'string', 'children': [], 'value': "'HOMEDRIVE'"}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'home'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'HOMEPATH'"}, {'id': '85', 'type': 'string', 'children': [], 'value': "''"}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'home'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'home'}; {'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': 'join'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_win_drive'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'home'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'home'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'HOME'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "''"}, {'id': '113', 'type': 'if_statement', 'children': ['114', '116']}; {'id': '114', 'type': 'not_operator', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'home'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'home'}; {'id': '120', 'type': 'call', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'~'"}; {'id': '128', 'type': 'if_statement', 'children': ['129', '131']}, {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'home'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'string', 'children': [], 'value': "''"}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 've_base'}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'home'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'.virtualenvs'"}; {'id': '146', 'type': 'return_statement', 'children': ['147']}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '149'], 'value': 'or'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 've_base'}, {'id': '149', 'type': 'string', 'children': [], 'value': "''"} | def get_ve_base(self, environ):
ve_base_value = self.headings[self.default_heading].get('virtualenvs')
if ve_base_value:
ve_base = os.path.expanduser(ve_base_value)
else:
ve_base = environ.get('WORKON_HOME', '')
if not ve_base:
if platform.system() == 'Windows' and os.name == 'nt':
_win_drive = environ.get('HOMEDRIVE')
home = environ.get('HOMEPATH', '')
if home:
home = os.path.join(_win_drive, home)
else:
home = environ.get('HOME', '')
if not home:
home = os.path.expanduser('~')
if not home:
return ''
ve_base = os.path.join(home, '.virtualenvs')
return ve_base or '' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'block', 'children': ['12', '62', '91', '131', '135', '177']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18', '24', '40']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '17'], 'value': 'is'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '17', 'type': 'None', 'children': []}; {'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': 'RuntimeError'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'generate() called with no path specified'"}; {'id': '24', 'type': 'elif_clause', 'children': ['25', '30']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '<='}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'PathEmptyError'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'elif_clause', 'children': ['41', '52']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '48']}, {'id': '43', 'type': 'attribute', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PathNotFoundError'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66', '81']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '65', 'type': 'None', 'children': []}; {'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': 'cancel'}; {'id': '70', 'type': 'lambda', 'children': ['71', '74']}, {'id': '71', 'type': 'lambda_parameters', 'children': ['72']}; {'id': '72', 'type': 'list_splat_pattern', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '80'], 'value': 'is'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'list_splat', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'else_clause', 'children': ['82']}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cancel'}; {'id': '86', 'type': 'lambda', 'children': ['87', '90']}, {'id': '87', 'type': 'lambda_parameters', 'children': ['88']}; {'id': '88', 'type': 'list_splat_pattern', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '90', 'type': 'False', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '102', '111']}; {'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': 'isfile'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'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': '_set_pieces_singlefile'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'elif_clause', 'children': ['112', '122']}; {'id': '112', 'type': 'call', 'children': ['113', '118']}, {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'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': 'path'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_set_pieces_multifile'}; {'id': '130', 'type': 'argument_list', 'children': []}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'last_cb_call'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'for_statement', 'children': ['136', '140', '141']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'pieces_done'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'pieces_total'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '141', 'type': 'block', 'children': ['142', '150']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '161']}, {'id': '151', 'type': 'boolean_operator', 'children': ['152', '157', '158'], 'value': 'or'}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '156'], 'value': '>='}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '-'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'last_cb_call'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '157', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '>='}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'pieces_done'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'pieces_total'}, {'id': '161', 'type': 'block', 'children': ['162', '166']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'last_cb_call'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '174']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cancel'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '173']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pieces_done'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'pieces_total'}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'False', 'children': []}, {'id': '177', 'type': 'return_statement', 'children': ['178']} | def generate(self, callback=None, interval=0):
if self.path is None:
raise RuntimeError('generate() called with no path specified')
elif self.size <= 0:
raise error.PathEmptyError(self.path)
elif not os.path.exists(self.path):
raise error.PathNotFoundError(self.path)
if callback is not None:
cancel = lambda *status: callback(*status) is not None
else:
cancel = lambda *status: False
if os.path.isfile(self.path):
pieces = self._set_pieces_singlefile()
elif os.path.isdir(self.path):
pieces = self._set_pieces_multifile()
last_cb_call = 0
for filepath,pieces_done,pieces_total in pieces:
now = time.time()
if now - last_cb_call >= interval or \
pieces_done >= pieces_total:
last_cb_call = now
if cancel(self, filepath, pieces_done, pieces_total):
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_stream'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'try_statement', 'children': ['11', '23', '38']}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'MAX_TORRENT_FILE_SIZE'}, {'id': '23', 'type': 'except_clause', 'children': ['24', '28']}; {'id': '24', 'type': 'as_pattern', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '26', 'type': 'as_pattern_target', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ReadError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}, {'id': '39', 'type': 'block', 'children': ['40', '61', '109', '159', '165', '171', '188', '196', '227', '236']}; {'id': '40', 'type': 'try_statement', 'children': ['41', '49']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'bdecode'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '49', 'type': 'except_clause', 'children': ['50', '54']}; {'id': '50', 'type': 'as_pattern', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'BTFailure'}; {'id': '52', 'type': 'as_pattern_target', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'raise_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ParseError'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'if_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68', '76', '95']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'not'}; {'id': '66', 'type': 'string', 'children': [], 'value': "b'info'"}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'raise_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'MetainfoError'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'string', 'children': [], 'value': '"Missing \'info\'"'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '87']}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '84']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}, {'id': '83', 'type': 'string', 'children': [], 'value': "b'info'"}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'abc'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'Mapping'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'MetainfoError'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"\'info\' is not a dictionary"'}, {'id': '95', 'type': 'elif_clause', 'children': ['96', '101']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'}, {'id': '97', 'type': 'string', 'children': [], 'value': "b'pieces'"}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}; {'id': '100', 'type': 'string', 'children': [], 'value': "b'info'"}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'MetainfoError'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"Missing \'pieces\' in [\'info\']"'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '119', '148']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '114'], 'value': 'and'}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'string', 'children': [], 'value': "b'info'"}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'in'}, {'id': '115', 'type': 'string', 'children': [], 'value': "b'pieces'"}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}; {'id': '118', 'type': 'string', 'children': [], 'value': "b'info'"}, {'id': '119', 'type': 'block', 'children': ['120', '131', '140']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pieces'}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}, {'id': '127', 'type': 'string', 'children': [], 'value': "b'info'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "b'pieces'"}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'metainfo'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'decode_dict'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '147']}; {'id': '142', 'type': 'subscript', 'children': ['143', '146']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'metainfo'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'info'"}; {'id': '146', 'type': 'string', 'children': [], 'value': "'pieces'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'pieces'}; {'id': '148', 'type': 'else_clause', 'children': ['149']}, {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'metainfo'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'decode_dict'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'metainfo_enc'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'torrent'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'torrent'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': '_metainfo'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'metainfo'}, {'id': '171', 'type': 'for_statement', 'children': ['172', '173', '176']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '173', 'type': 'tuple', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'creation_date'"}, {'id': '175', 'type': 'string', 'children': [], 'value': "'private'"}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182', '183']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'torrent'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'torrent'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '191', 'type': 'subscript', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'torrent'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'metainfo'}, {'id': '195', 'type': 'string', 'children': [], 'value': "'info'"}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'torrent'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'include_md5'}, {'id': '201', 'type': 'boolean_operator', 'children': ['202', '210', '211'], 'value': 'or'}; {'id': '202', 'type': 'parenthesized_expression', 'children': ['203']}, {'id': '203', 'type': 'boolean_operator', 'children': ['204', '207'], 'value': 'and'}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'in'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'in'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'md5sum'"}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '210', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '211', 'type': 'parenthesized_expression', 'children': ['212']}; {'id': '212', 'type': 'boolean_operator', 'children': ['213', '216'], 'value': 'and'}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'in'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'files'"}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '218', 'type': 'generator_expression', 'children': ['219', '222']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'in'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'md5sum'"}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'fileinfo'}; {'id': '222', 'type': 'for_in_clause', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'fileinfo'}; {'id': '224', 'type': 'subscript', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'files'"}, {'id': '227', 'type': 'if_statement', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'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': 'torrent'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '235', 'type': 'argument_list', 'children': []}; {'id': '236', 'type': 'return_statement', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'torrent'} | def read_stream(cls, stream, validate=True):
try:
content = stream.read(cls.MAX_TORRENT_FILE_SIZE)
except OSError as e:
raise error.ReadError(e.errno)
else:
try:
metainfo_enc = bdecode(content)
except BTFailure as e:
raise error.ParseError()
if validate:
if b'info' not in metainfo_enc:
raise error.MetainfoError("Missing 'info'")
elif not isinstance(metainfo_enc[b'info'], abc.Mapping):
raise error.MetainfoError("'info' is not a dictionary")
elif b'pieces' not in metainfo_enc[b'info']:
raise error.MetainfoError("Missing 'pieces' in ['info']")
if b'info' in metainfo_enc and b'pieces' in metainfo_enc[b'info']:
pieces = metainfo_enc[b'info'].pop(b'pieces')
metainfo = utils.decode_dict(metainfo_enc)
metainfo['info']['pieces'] = pieces
else:
metainfo = utils.decode_dict(metainfo_enc)
torrent = cls()
torrent._metainfo = metainfo
for attr in ('creation_date', 'private'):
setattr(torrent, attr, getattr(torrent, attr))
info = torrent.metainfo['info']
torrent.include_md5 = ('length' in info and 'md5sum' in info) or \
('files' in info and all('md5sum' in fileinfo
for fileinfo in info['files']))
if validate:
torrent.validate()
return torrent |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filepaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '7', 'type': 'tuple', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'hidden'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '64']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '25', '33']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'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': 'os'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'raise_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'PathNotFoundError'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '33', 'type': 'elif_clause', 'children': ['34', '53']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'access'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'R_OK'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'effective_ids'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'in'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'access'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'supports_effective_ids'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'raise_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ReadError'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'EACCES'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '73', '77']}, {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isfile'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'list', 'children': ['76'], 'value': '[path]'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '77', 'type': 'else_clause', 'children': ['78']}; {'id': '78', 'type': 'block', 'children': ['79', '83', '175']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'filepaths'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'for_statement', 'children': ['84', '88', '94']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86', '87']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'dirpath'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'dirnames'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '94', 'type': 'block', 'children': ['95', '105']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '103']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '99'], 'value': 'and'}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'hidden'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'is_hidden'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dirpath'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'continue_statement', 'children': []}, {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '108', 'type': 'block', 'children': ['109', '119', '131']}, {'id': '109', 'type': 'if_statement', 'children': ['110', '117']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '113'], 'value': 'and'}, {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'hidden'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'is_hidden'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'continue_statement', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dirpath'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '131', 'type': 'if_statement', 'children': ['132', '143', '145']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '134', 'type': 'generator_expression', 'children': ['135', '140']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_match'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'continue_statement', 'children': []}, {'id': '145', 'type': 'else_clause', 'children': ['146']}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'if_statement', 'children': ['148', '167']}; {'id': '148', 'type': 'boolean_operator', 'children': ['149', '150'], 'value': 'or'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '166'], 'value': '>'}, {'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': 'os'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'getsize'}, {'id': '157', 'type': 'argument_list', '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': 'os'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'realpath'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'filepaths'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'filepaths'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '182', 'type': 'lambda', 'children': ['183', '185']}, {'id': '183', 'type': 'lambda_parameters', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'casefold'}, {'id': '189', 'type': 'argument_list', 'children': []} | def filepaths(path, exclude=(), hidden=True, empty=True):
if not os.path.exists(path):
raise error.PathNotFoundError(path)
elif not os.access(path, os.R_OK,
effective_ids=os.access in os.supports_effective_ids):
raise error.ReadError(errno.EACCES, path)
if os.path.isfile(path):
return [path]
else:
filepaths = []
for dirpath, dirnames, filenames in os.walk(path):
if not hidden and is_hidden(dirpath):
continue
for filename in filenames:
if not hidden and is_hidden(filename):
continue
filepath = os.path.join(dirpath, filename)
if any(is_match(filepath, pattern) for pattern in exclude):
continue
else:
if empty or os.path.getsize(os.path.realpath(filepath)) > 0:
filepaths.append(filepath)
return sorted(filepaths, key=lambda fp: fp.casefold()) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'}, {'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': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '28', '50', '77']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '15']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'CAS_FEDERATE'}, {'id': '15', 'type': 'block', 'children': ['16', '23']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"CAS_FEDERATE is False, set it to True to use federation"'}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'renew'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'boolean_operator', 'children': ['35', '43'], 'value': 'and'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'renew'"}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '49'], 'value': '!='}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'renew'"}, {'id': '49', 'type': 'string', 'children': [], 'value': '"False"'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '64']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '62'], 'value': 'and'}; {'id': '52', 'type': 'call', 'children': ['53', '60']}, {'id': '53', 'type': 'attribute', 'children': ['54', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"authenticated"'}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'renew'}; {'id': '64', 'type': 'block', 'children': ['65', '72']}, {'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': 'logger'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'string', 'children': [], 'value': '"User already authenticated, dropping federated authentication request"'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'redirect'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}, {'id': '77', 'type': 'try_statement', 'children': ['78', '343']}; {'id': '78', 'type': 'block', 'children': ['79', '92', '103']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'FederatedIendityProvider'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'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': 'get_cas_client'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'renew'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '109', '132']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'not'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'ticket'"}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '109', 'type': 'block', 'children': ['110', '123']}; {'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': 'logger'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'}, {'id': '117', 'type': 'string', 'children': [], 'value': '"Trying to authenticate %s again"'}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'server_url'}, {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_login_url'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'else_clause', 'children': ['133']}, {'id': '133', 'type': 'block', 'children': ['134', '142']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ticket'}, {'id': '137', 'type': 'subscript', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'ticket'"}; {'id': '142', 'type': 'try_statement', 'children': ['143', '297']}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'if_statement', 'children': ['145', '151', '265']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'verify_ticket'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ticket'}, {'id': '151', 'type': 'block', 'children': ['152', '169', '185', '195', '203', '218', '228', '235', '263']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"Got a valid ticket for %s from %s"'}; {'id': '160', 'type': 'tuple', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'server_url'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'copy_params'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '182', 'type': 'set', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': '"ticket"'}; {'id': '184', 'type': 'string', 'children': [], 'value': '"remember"'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '192']}, {'id': '187', 'type': 'subscript', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '191', 'type': 'string', 'children': [], 'value': '"federate_username"'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'federated_username'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '202']}, {'id': '197', 'type': 'subscript', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '201', 'type': 'string', 'children': [], 'value': '"federate_ticket"'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ticket'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'register_slo'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212', '217']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'federated_username'}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'session_key'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ticket'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'reverse_params'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '235', 'type': 'if_statement', 'children': ['236', '244']}; {'id': '236', 'type': 'call', 'children': ['237', '242']}, {'id': '237', 'type': 'attribute', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'string', 'children': [], 'value': '"remember"'}; {'id': '244', 'type': 'block', 'children': ['245', '251']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'CAS_FEDERATE_REMEMBER_TIMEOUT'}, {'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': 'utils'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'set_cookie'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259', '262']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '258', 'type': 'string', 'children': [], 'value': '"remember_provider"'}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'provider'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '263', 'type': 'return_statement', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '265', 'type': 'else_clause', 'children': ['266']}; {'id': '266', 'type': 'block', 'children': ['267', '288']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'binary_operator', 'children': ['274', '278'], 'value': '%'}; {'id': '274', 'type': 'parenthesized_expression', 'children': ['275']}, {'id': '275', 'type': 'concatenated_string', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': '"Got an invalid ticket %s from %s for service %s. "'}, {'id': '277', 'type': 'string', 'children': [], 'value': '"Retrying authentication"'}; {'id': '278', 'type': 'tuple', 'children': ['279', '280', '285']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'ticket'}; {'id': '280', 'type': 'attribute', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'server_url'}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'service_url'}; {'id': '288', 'type': 'return_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'get_login_url'}; {'id': '296', 'type': 'argument_list', 'children': []}, {'id': '297', 'type': 'except_clause', 'children': ['298', '302']}; {'id': '298', 'type': 'as_pattern', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '300', 'type': 'as_pattern_target', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '302', 'type': 'block', 'children': ['303', '327', '334', '341']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'add_message'}; {'id': '308', 'type': 'argument_list', 'children': ['309', '310', '313']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'ERROR'}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '320'], 'value': '%'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'concatenated_string', 'children': ['318', '319']}; {'id': '318', 'type': 'string', 'children': [], 'value': 'u"Invalid response from your identity provider CAS upon "'}, {'id': '319', 'type': 'string', 'children': [], 'value': 'u"ticket %(ticket)s validation: %(error)r"'}; {'id': '320', 'type': 'dictionary', 'children': ['321', '324']}, {'id': '321', 'type': 'pair', 'children': ['322', '323']}; {'id': '322', 'type': 'string', 'children': [], 'value': "'ticket'"}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'ticket'}; {'id': '324', 'type': 'pair', 'children': ['325', '326']}, {'id': '325', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'delete_cookie'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'string', 'children': [], 'value': '"remember_provider"'}, {'id': '341', 'type': 'return_statement', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '343', 'type': 'except_clause', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'FederatedIendityProvider'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}, {'id': '347', 'type': 'block', 'children': ['348', '357']}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'call', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'binary_operator', 'children': ['355', '356'], 'value': '%'}, {'id': '355', 'type': 'string', 'children': [], 'value': '"Identity provider suffix %s not found"'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'provider'}, {'id': '357', 'type': 'return_statement', 'children': ['358']}; {'id': '358', 'type': 'call', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}, {'id': '361', 'type': 'string', 'children': [], 'value': '"cas_server:login"'} | def get(self, request, provider=None):
if not settings.CAS_FEDERATE:
logger.warning("CAS_FEDERATE is False, set it to True to use federation")
return redirect("cas_server:login")
renew = bool(request.GET.get('renew') and request.GET['renew'] != "False")
if self.request.session.get("authenticated") and not renew:
logger.warning("User already authenticated, dropping federated authentication request")
return redirect("cas_server:login")
try:
provider = FederatedIendityProvider.objects.get(suffix=provider)
auth = self.get_cas_client(request, provider, renew)
if 'ticket' not in request.GET:
logger.info("Trying to authenticate %s again" % auth.provider.server_url)
return HttpResponseRedirect(auth.get_login_url())
else:
ticket = request.GET['ticket']
try:
if auth.verify_ticket(ticket):
logger.info(
"Got a valid ticket for %s from %s" % (
auth.username,
auth.provider.server_url
)
)
params = utils.copy_params(request.GET, ignore={"ticket", "remember"})
request.session["federate_username"] = auth.federated_username
request.session["federate_ticket"] = ticket
auth.register_slo(
auth.federated_username,
request.session.session_key,
ticket
)
url = utils.reverse_params("cas_server:login", params)
response = HttpResponseRedirect(url)
if request.GET.get("remember"):
max_age = settings.CAS_FEDERATE_REMEMBER_TIMEOUT
utils.set_cookie(
response,
"remember_provider",
provider.suffix,
max_age
)
return response
else:
logger.info(
(
"Got an invalid ticket %s from %s for service %s. "
"Retrying authentication"
) % (
ticket,
auth.provider.server_url,
self.service_url
)
)
return HttpResponseRedirect(auth.get_login_url())
except SyntaxError as error:
messages.add_message(
request,
messages.ERROR,
_(
u"Invalid response from your identity provider CAS upon "
u"ticket %(ticket)s validation: %(error)r"
) % {'ticket': ticket, 'error': error}
)
response = redirect("cas_server:login")
response.delete_cookie("remember_provider")
return response
except FederatedIendityProvider.DoesNotExist:
logger.warning("Identity provider suffix %s not found" % provider)
return redirect("cas_server:login") |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'service_login'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '347', '376']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '231', '263', '288', '313']}, {'id': '7', 'type': 'block', 'children': ['8', '19', '28']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ServicePattern'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'service'}, {'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': 'service_pattern'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'check_user'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '45', '164']}, {'id': '29', 'type': 'boolean_operator', 'children': ['30', '41'], 'value': 'and'}; {'id': '30', 'type': 'call', 'children': ['31', '38']}, {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': '"warn"'}; {'id': '40', 'type': 'True', 'children': []}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'warned'}, {'id': '45', 'type': 'block', 'children': ['46', '74']}; {'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': 'messages'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '55', '58']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'WARNING'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '63'], 'value': '%'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': 'u"Authentication has been required by service %(name)s (%(url)s)"'}, {'id': '63', 'type': 'dictionary', 'children': ['64', '69']}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'url'"}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78', '97']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ajax'}; {'id': '78', 'type': 'block', 'children': ['79', '89']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '82', 'type': 'dictionary', 'children': ['83', '86']}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"detail"'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"confirmation needed"'}, {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'json_response'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99', '145']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'warn_form'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'forms'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'WarnForm'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'initial'}, {'id': '109', 'type': 'dictionary', 'children': ['110', '115', '120', '125', '130', '133']}; {'id': '110', 'type': 'pair', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'service'"}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '115', 'type': 'pair', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'renew'"}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'renew'}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'gateway'"}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'gateway'}, {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'method'"}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '130', 'type': 'pair', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'warned'"}; {'id': '132', 'type': 'True', 'children': []}, {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'lt'"}, {'id': '135', 'type': 'subscript', 'children': ['136', '143']}; {'id': '136', 'type': 'subscript', 'children': ['137', '142']}, {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'lt'"}, {'id': '143', 'type': 'unary_operator', 'children': ['144'], 'value': '-'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '145', 'type': 'return_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '152', '155']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'CAS_WARN_TEMPLATE'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'dictionary', 'children': ['161']}, {'id': '161', 'type': 'pair', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'form'"}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'warn_form'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166', '178', '197']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_messages'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '181', 'type': 'call', 'children': ['182', '187']}; {'id': '182', 'type': 'attribute', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'get_service_url'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '191', '192']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'renew'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'renewed'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '202', '208']}; {'id': '198', 'type': 'not_operator', 'children': ['199']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ajax'}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'return_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '208', 'type': 'else_clause', 'children': ['209']}, {'id': '209', 'type': 'block', 'children': ['210', '223']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '213', 'type': 'dictionary', 'children': ['214', '217', '220']}; {'id': '214', 'type': 'pair', 'children': ['215', '216']}, {'id': '215', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '216', 'type': 'string', 'children': [], 'value': '"success"'}, {'id': '217', 'type': 'pair', 'children': ['218', '219']}; {'id': '218', 'type': 'string', 'children': [], 'value': '"detail"'}, {'id': '219', 'type': 'string', 'children': [], 'value': '"auth"'}; {'id': '220', 'type': 'pair', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': '"url"'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'json_response'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '231', 'type': 'except_clause', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ServicePattern'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}, {'id': '235', 'type': 'block', 'children': ['236', '240']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'messages'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '245', 'type': 'argument_list', 'children': ['246', '249', '252']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ERROR'}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '257'], 'value': '%'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'string', 'children': [], 'value': "u'Service %(url)s not allowed.'"}, {'id': '257', 'type': 'dictionary', 'children': ['258']}; {'id': '258', 'type': 'pair', 'children': ['259', '260']}, {'id': '259', 'type': 'string', 'children': [], 'value': "'url'"}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '263', 'type': 'except_clause', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'BadUsername'}, {'id': '267', 'type': 'block', 'children': ['268', '272']}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '271', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '281', '284']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'ERROR'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'string', 'children': [], 'value': 'u"Username not allowed"'}; {'id': '288', 'type': 'except_clause', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'BadFilter'}; {'id': '292', 'type': 'block', 'children': ['293', '297']}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'add_message'}; {'id': '302', 'type': 'argument_list', 'children': ['303', '306', '309']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'ERROR'}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'string', 'children': [], 'value': 'u"User characteristics not allowed"'}, {'id': '313', 'type': 'except_clause', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'UserFieldNotDefined'}, {'id': '317', 'type': 'block', 'children': ['318', '322']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '321', 'type': 'integer', 'children': [], 'value': '4'}; {'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': 'messages'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '331', '334']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'ERROR'}; {'id': '334', 'type': 'binary_operator', 'children': ['335', '341'], 'value': '%'}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'concatenated_string', 'children': ['339', '340']}, {'id': '339', 'type': 'string', 'children': [], 'value': 'u"The attribute %(field)s is needed to use"'}; {'id': '340', 'type': 'string', 'children': [], 'value': 'u" that service"'}, {'id': '341', 'type': 'dictionary', 'children': ['342']}; {'id': '342', 'type': 'pair', 'children': ['343', '344']}, {'id': '343', 'type': 'string', 'children': [], 'value': "'field'"}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'user_field'}, {'id': '347', 'type': 'if_statement', 'children': ['348', '356']}; {'id': '348', 'type': 'boolean_operator', 'children': ['349', '352'], 'value': 'and'}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'gateway'}; {'id': '352', 'type': 'not_operator', 'children': ['353']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'ajax'}; {'id': '356', 'type': 'block', 'children': ['357', '369']}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'call', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'get_messages'}, {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '369', 'type': 'return_statement', 'children': ['370']}; {'id': '370', 'type': 'call', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '372', 'type': 'argument_list', 'children': ['373']}, {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '376', 'type': 'if_statement', 'children': ['377', '381', '405']}, {'id': '377', 'type': 'not_operator', 'children': ['378']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'ajax'}, {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'return_statement', 'children': ['383']}, {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '385', 'type': 'argument_list', 'children': ['386', '389', '392']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'CAS_LOGGED_TEMPLATE'}; {'id': '392', 'type': 'call', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'dictionary', 'children': ['398']}; {'id': '398', 'type': 'pair', 'children': ['399', '400']}, {'id': '399', 'type': 'string', 'children': [], 'value': "'session'"}; {'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': 'request'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '405', 'type': 'else_clause', 'children': ['406']}; {'id': '406', 'type': 'block', 'children': ['407', '420']}, {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'assignment', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '410', 'type': 'dictionary', 'children': ['411', '414', '417']}, {'id': '411', 'type': 'pair', 'children': ['412', '413']}; {'id': '412', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '413', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '414', 'type': 'pair', 'children': ['415', '416']}, {'id': '415', 'type': 'string', 'children': [], 'value': '"detail"'}; {'id': '416', 'type': 'string', 'children': [], 'value': '"auth"'}, {'id': '417', 'type': 'pair', 'children': ['418', '419']}; {'id': '418', 'type': 'string', 'children': [], 'value': '"code"'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '420', 'type': 'return_statement', 'children': ['421']}, {'id': '421', 'type': 'call', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'json_response'}, {'id': '423', 'type': 'argument_list', 'children': ['424', '427']}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'data'} | def service_login(self):
try:
service_pattern = ServicePattern.validate(self.service)
service_pattern.check_user(self.user)
if self.request.session.get("warn", True) and not self.warned:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication has been required by service %(name)s (%(url)s)") %
{'name': service_pattern.name, 'url': self.service}
)
if self.ajax:
data = {"status": "error", "detail": "confirmation needed"}
return json_response(self.request, data)
else:
warn_form = forms.WarnForm(initial={
'service': self.service,
'renew': self.renew,
'gateway': self.gateway,
'method': self.method,
'warned': True,
'lt': self.request.session['lt'][-1]
})
return render(
self.request,
settings.CAS_WARN_TEMPLATE,
utils.context({'form': warn_form})
)
else:
list(messages.get_messages(self.request))
redirect_url = self.user.get_service_url(
self.service,
service_pattern,
renew=self.renewed
)
if not self.ajax:
return HttpResponseRedirect(redirect_url)
else:
data = {"status": "success", "detail": "auth", "url": redirect_url}
return json_response(self.request, data)
except ServicePattern.DoesNotExist:
error = 1
messages.add_message(
self.request,
messages.ERROR,
_(u'Service %(url)s not allowed.') % {'url': self.service}
)
except models.BadUsername:
error = 2
messages.add_message(
self.request,
messages.ERROR,
_(u"Username not allowed")
)
except models.BadFilter:
error = 3
messages.add_message(
self.request,
messages.ERROR,
_(u"User characteristics not allowed")
)
except models.UserFieldNotDefined:
error = 4
messages.add_message(
self.request,
messages.ERROR,
_(u"The attribute %(field)s is needed to use"
u" that service") % {'field': service_pattern.user_field}
)
if self.gateway and not self.ajax:
list(messages.get_messages(self.request))
return HttpResponseRedirect(self.service)
if not self.ajax:
return render(
self.request,
settings.CAS_LOGGED_TEMPLATE,
utils.context({'session': self.request.session})
)
else:
data = {"status": "error", "detail": "auth", "code": error}
return json_response(self.request, data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'not_authenticated'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '162']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'try_statement', 'children': ['12', '132']}; {'id': '12', 'type': 'block', 'children': ['13', '24', '53']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ServicePattern'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '33']}, {'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'gateway'}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ajax'}, {'id': '33', 'type': 'block', 'children': ['34', '46']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_messages'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'CAS_SHOW_SERVICE_MESSAGES'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '73', '102']}, {'id': '59', 'type': 'boolean_operator', 'children': ['60', '70'], 'value': 'and'}; {'id': '60', 'type': 'call', 'children': ['61', '68']}, {'id': '61', 'type': 'attribute', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"authenticated"'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'renew'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83', '86']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'WARNING'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '91'], 'value': '%'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': 'u"Authentication renewal required by service %(name)s (%(url)s)."'}, {'id': '91', 'type': 'dictionary', 'children': ['92', '97']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'url'"}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'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': 'messages'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '113', '116']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'WARNING'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '%'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': 'u"Authentication required by service %(name)s (%(url)s)."'}, {'id': '121', 'type': 'dictionary', 'children': ['122', '127']}; {'id': '122', 'type': 'pair', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'service_pattern'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '127', 'type': 'pair', 'children': ['128', '129']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'url'"}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '132', 'type': 'except_clause', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ServicePattern'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'if_statement', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'CAS_SHOW_SERVICE_MESSAGES'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'add_message'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '151', '154']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ERROR'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '159'], 'value': '%'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'string', 'children': [], 'value': "u'Service %s not allowed'"}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '166', '200']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ajax'}; {'id': '166', 'type': 'block', 'children': ['167', '192']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '170', 'type': 'dictionary', 'children': ['171', '174', '177']}, {'id': '171', 'type': 'pair', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '173', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '174', 'type': 'pair', 'children': ['175', '176']}, {'id': '175', 'type': 'string', 'children': [], 'value': '"detail"'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"login required"'}, {'id': '177', 'type': 'pair', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': '"url"'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'reverse_params'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}, {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'params'}, {'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': 'request'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'json_response'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '200', 'type': 'else_clause', 'children': ['201']}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'if_statement', 'children': ['203', '206', '435']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'CAS_FEDERATE'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'if_statement', 'children': ['208', '215', '246']}; {'id': '208', 'type': 'boolean_operator', 'children': ['209', '212'], 'value': 'and'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'ticket'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'return_statement', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '223', '226']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'CAS_LOGIN_TEMPLATE'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'dictionary', 'children': ['232', '237', '240']}; {'id': '232', 'type': 'pair', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': "'form'"}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '237', 'type': 'pair', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'auto_submit'"}, {'id': '239', 'type': 'True', 'children': []}; {'id': '240', 'type': 'pair', 'children': ['241', '242']}, {'id': '241', 'type': 'string', 'children': [], 'value': "'post_url'"}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'string', 'children': [], 'value': '"cas_server:login"'}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '277', '322']}, {'id': '249', 'type': 'parenthesized_expression', 'children': ['250']}; {'id': '250', 'type': 'boolean_operator', 'children': ['251', '261'], 'value': 'and'}, {'id': '251', 'type': 'call', 'children': ['252', '259']}; {'id': '252', 'type': 'attribute', 'children': ['253', '258']}, {'id': '253', 'type': 'attribute', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'COOKIES'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'remember_provider'"}, {'id': '261', 'type': 'call', 'children': ['262', '267']}; {'id': '262', 'type': 'attribute', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'FederatedIendityProvider'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '270', 'type': 'subscript', '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': 'request'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'COOKIES'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'remember_provider'"}, {'id': '277', 'type': 'block', 'children': ['278', '291', '317']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'copy_params'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'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': 'request'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'reverse_params'}; {'id': '298', 'type': 'argument_list', 'children': ['299', '300', '303']}, {'id': '299', 'type': 'string', 'children': [], 'value': '"cas_server:federateAuth"'}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '310', 'type': 'subscript', 'children': ['311', '316']}, {'id': '311', 'type': 'attribute', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'COOKIES'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'remember_provider'"}, {'id': '317', 'type': 'return_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '322', 'type': 'else_clause', 'children': ['323']}, {'id': '323', 'type': 'block', 'children': ['324', '408']}; {'id': '324', 'type': 'if_statement', 'children': ['325', '339']}, {'id': '325', 'type': 'boolean_operator', 'children': ['326', '329'], 'value': 'and'}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'renew'}, {'id': '329', 'type': 'call', 'children': ['330', '337']}; {'id': '330', 'type': 'attribute', 'children': ['331', '336']}, {'id': '331', 'type': 'attribute', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'string', 'children': [], 'value': '"authenticated"'}, {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'try_statement', 'children': ['341', '402']}, {'id': '341', 'type': 'block', 'children': ['342', '360', '373', '397']}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'assignment', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'FederatedUser'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'get_from_federated_username'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '358']}, {'id': '351', 'type': 'attribute', 'children': ['352', '357']}; {'id': '352', 'type': 'attribute', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'string', 'children': [], 'value': '"username"'}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'assignment', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '363', 'type': 'call', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'copy_params'}, {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'attribute', 'children': ['369', '372']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'assignment', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '376', 'type': 'call', 'children': ['377', '380']}, {'id': '377', 'type': 'attribute', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'reverse_params'}; {'id': '380', 'type': 'argument_list', 'children': ['381', '382', '385']}, {'id': '381', 'type': 'string', 'children': [], 'value': '"cas_server:federateAuth"'}; {'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '385', 'type': 'keyword_argument', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '387', 'type': 'call', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '389', 'type': 'argument_list', 'children': ['390']}; {'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '392', 'type': 'attribute', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'provider'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '397', 'type': 'return_statement', 'children': ['398']}; {'id': '398', 'type': 'call', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '400', 'type': 'argument_list', 'children': ['401']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '402', 'type': 'except_clause', 'children': ['403', '406']}, {'id': '403', 'type': 'attribute', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'FederatedUser'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}; {'id': '406', 'type': 'block', 'children': ['407']}, {'id': '407', 'type': 'pass_statement', 'children': []}; {'id': '408', 'type': 'return_statement', 'children': ['409']}, {'id': '409', 'type': 'call', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '411', 'type': 'argument_list', 'children': ['412', '415', '418']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'CAS_LOGIN_TEMPLATE'}; {'id': '418', 'type': 'call', 'children': ['419', '422']}, {'id': '419', 'type': 'attribute', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '422', 'type': 'argument_list', 'children': ['423']}, {'id': '423', 'type': 'dictionary', 'children': ['424', '429']}; {'id': '424', 'type': 'pair', 'children': ['425', '426']}, {'id': '425', 'type': 'string', 'children': [], 'value': "'form'"}; {'id': '426', 'type': 'attribute', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '429', 'type': 'pair', 'children': ['430', '431']}; {'id': '430', 'type': 'string', 'children': [], 'value': "'post_url'"}, {'id': '431', 'type': 'call', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '433', 'type': 'argument_list', 'children': ['434']}; {'id': '434', 'type': 'string', 'children': [], 'value': '"cas_server:federateAuth"'}, {'id': '435', 'type': 'else_clause', 'children': ['436']}; {'id': '436', 'type': 'block', 'children': ['437']}, {'id': '437', 'type': 'return_statement', 'children': ['438']}; {'id': '438', 'type': 'call', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '440', 'type': 'argument_list', 'children': ['441', '444', '447']}, {'id': '441', 'type': 'attribute', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '444', 'type': 'attribute', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'CAS_LOGIN_TEMPLATE'}, {'id': '447', 'type': 'call', 'children': ['448', '451']}; {'id': '448', 'type': 'attribute', 'children': ['449', '450']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '451', 'type': 'argument_list', 'children': ['452']}; {'id': '452', 'type': 'dictionary', 'children': ['453']}, {'id': '453', 'type': 'pair', 'children': ['454', '455']}; {'id': '454', 'type': 'string', 'children': [], 'value': "'form'"}, {'id': '455', 'type': 'attribute', 'children': ['456', '457']}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'form'} | def not_authenticated(self):
if self.service:
try:
service_pattern = ServicePattern.validate(self.service)
if self.gateway and not self.ajax:
list(messages.get_messages(self.request))
return HttpResponseRedirect(self.service)
if settings.CAS_SHOW_SERVICE_MESSAGES:
if self.request.session.get("authenticated") and self.renew:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication renewal required by service %(name)s (%(url)s).") %
{'name': service_pattern.name, 'url': self.service}
)
else:
messages.add_message(
self.request,
messages.WARNING,
_(u"Authentication required by service %(name)s (%(url)s).") %
{'name': service_pattern.name, 'url': self.service}
)
except ServicePattern.DoesNotExist:
if settings.CAS_SHOW_SERVICE_MESSAGES:
messages.add_message(
self.request,
messages.ERROR,
_(u'Service %s not allowed') % self.service
)
if self.ajax:
data = {
"status": "error",
"detail": "login required",
"url": utils.reverse_params("cas_server:login", params=self.request.GET)
}
return json_response(self.request, data)
else:
if settings.CAS_FEDERATE:
if self.username and self.ticket:
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({
'form': self.form,
'auto_submit': True,
'post_url': reverse("cas_server:login")
})
)
else:
if (
self.request.COOKIES.get('remember_provider') and
FederatedIendityProvider.objects.filter(
suffix=self.request.COOKIES['remember_provider']
)
):
params = utils.copy_params(self.request.GET)
url = utils.reverse_params(
"cas_server:federateAuth",
params=params,
kwargs=dict(provider=self.request.COOKIES['remember_provider'])
)
return HttpResponseRedirect(url)
else:
if self.renew and self.request.session.get("authenticated"):
try:
user = FederatedUser.get_from_federated_username(
self.request.session.get("username")
)
params = utils.copy_params(self.request.GET)
url = utils.reverse_params(
"cas_server:federateAuth",
params=params,
kwargs=dict(provider=user.provider.suffix)
)
return HttpResponseRedirect(url)
except FederatedUser.DoesNotExist:
pass
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({
'form': self.form,
'post_url': reverse("cas_server:federateAuth")
})
)
else:
return render(
self.request,
settings.CAS_LOGIN_TEMPLATE,
utils.context({'form': self.form})
) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_path_to_api_path'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path_definitions'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'base_path'}; {'id': '8', 'type': 'string', 'children': [], 'value': "''"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '22', '30', '164']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'assert_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'collections'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Mapping'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '37', '154']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'base_path'}, {'id': '37', 'type': 'block', 'children': ['38', '49', '55', '61', '143']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'normalized_target_path'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'NORMALIZE_SLASH_REGEX'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'target_path'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'for_statement', 'children': ['62', '65', '70']}; {'id': '62', 'type': 'pattern_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path_definitions'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71', '84', '108']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'full_path'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'NORMALIZE_SLASH_REGEX'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'base_path'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'path_to_regex'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '93', '99', '105']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'api_path'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'full_path'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'path_parameters'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'extract_path_parameters'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'operation_parameters'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'extract_operation_parameters'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112', '120']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'full_path'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'normalized_target_path'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '120', 'type': 'elif_clause', 'children': ['121', '127']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'normalized_target_path'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '134']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '132', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'normalized_target_path'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '148', 'type': 'slice', 'children': ['149', '153']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'base_path'}, {'id': '153', 'type': 'colon', 'children': []}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156', '160']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}, {'id': '159', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}, {'id': '163', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '170', '189', '201', '230', '244', '327']}, {'id': '165', 'type': 'boolean_operator', 'children': ['166', '168'], 'value': 'and'}; {'id': '166', 'type': 'not_operator', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}; {'id': '168', 'type': 'not_operator', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '170', 'type': 'block', 'children': ['171', '184']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'fstr'}; {'id': '174', 'type': 'call', 'children': ['175', '182']}, {'id': '175', 'type': 'attribute', 'children': ['176', '181']}; {'id': '176', 'type': 'subscript', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'MESSAGES'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '180', 'type': 'string', 'children': [], 'value': "'no_matching_paths_found'"}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '184', 'type': 'raise_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'LookupError'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'fstr'}, {'id': '189', 'type': 'elif_clause', 'children': ['190', '196']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '195'], 'value': '=='}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '201', 'type': 'elif_clause', 'children': ['202', '208']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '207'], 'value': '>'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'raise_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'MultiplePathsFound'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '221']}; {'id': '214', 'type': 'attribute', 'children': ['215', '220']}, {'id': '215', 'type': 'subscript', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'MESSAGES'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '219', 'type': 'string', 'children': [], 'value': "'multiple_paths_found'"}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'target_path'}, {'id': '223', 'type': 'list_comprehension', 'children': ['224', '227']}; {'id': '224', 'type': 'subscript', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths'}; {'id': '230', 'type': 'elif_clause', 'children': ['231', '237']}, {'id': '231', 'type': 'comparison_operator', 'children': ['232', '236'], 'value': '=='}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'return_statement', 'children': ['239']}, {'id': '239', 'type': 'subscript', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'elif_clause', 'children': ['245', '251']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '>'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '251', 'type': 'block', 'children': ['252', '261', '279', '290', '306']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'matches_by_path_size'}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '261', 'type': 'for_statement', 'children': ['262', '265', '266']}; {'id': '262', 'type': 'pattern_list', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '277']}, {'id': '269', 'type': 'attribute', 'children': ['270', '276']}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'matches_by_path_size'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'longest_match'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'matches_by_path_size'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'if_statement', 'children': ['291', '299']}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '298'], 'value': '=='}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'matches_by_path_size'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'longest_match'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'return_statement', 'children': ['301']}, {'id': '301', 'type': 'subscript', 'children': ['302', '305']}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'matches_by_path_size'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'longest_match'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '306', 'type': 'raise_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'MultiplePathsFound'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '318']}, {'id': '311', 'type': 'attribute', 'children': ['312', '317']}; {'id': '312', 'type': 'subscript', 'children': ['313', '316']}, {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'MESSAGES'}, {'id': '315', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '316', 'type': 'string', 'children': [], 'value': "'multiple_paths_found'"}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'target_path'}; {'id': '320', 'type': 'list_comprehension', 'children': ['321', '324']}, {'id': '321', 'type': 'subscript', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '323', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '324', 'type': 'for_in_clause', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}, {'id': '327', 'type': 'else_clause', 'children': ['328']}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'return_statement', 'children': ['330']}; {'id': '330', 'type': 'subscript', 'children': ['331', '334']}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'matching_api_paths_regex'}, {'id': '333', 'type': 'integer', 'children': [], 'value': '0'} | def match_path_to_api_path(path_definitions, target_path, base_path='',
context=None):
if context is None:
context = {}
assert isinstance(context, collections.Mapping)
if target_path.startswith(base_path):
normalized_target_path = re.sub(NORMALIZE_SLASH_REGEX, '/',
target_path)
matching_api_paths = list()
matching_api_paths_regex = list()
for p, v in path_definitions.items():
full_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + p)
r = path_to_regex(
api_path=full_path,
path_parameters=extract_path_parameters(v),
operation_parameters=extract_operation_parameters(v),
context=context,
)
if full_path == normalized_target_path:
matching_api_paths.append(p)
elif r.match(normalized_target_path):
matching_api_paths_regex.\
append((p, r.match(normalized_target_path)))
target_path = target_path[len(base_path):]
else:
matching_api_paths = []
matching_api_paths_regex = []
if not matching_api_paths and not matching_api_paths_regex:
fstr = MESSAGES['path']['no_matching_paths_found'].format(target_path)
raise LookupError(fstr)
elif len(matching_api_paths) == 1:
return matching_api_paths[0]
elif len(matching_api_paths) > 1:
raise MultiplePathsFound(
MESSAGES['path']['multiple_paths_found'].format(
target_path, [v[0] for v in matching_api_paths],
)
)
elif len(matching_api_paths_regex) == 1:
return matching_api_paths_regex[0][0]
elif len(matching_api_paths_regex) > 1:
matches_by_path_size = collections.defaultdict(list)
for path, match in matching_api_paths_regex:
matches_by_path_size[len(path)].append(path)
longest_match = max(matches_by_path_size.keys())
if len(matches_by_path_size[longest_match]) == 1:
return matches_by_path_size[longest_match][0]
raise MultiplePathsFound(
MESSAGES['path']['multiple_paths_found'].format(
target_path, [v[0] for v in matching_api_paths_regex],
)
)
else:
return matching_api_paths_regex[0][0] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_read_frame'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '35', '47', '51', '75', '87', '91', '104', '110', '129', '153', '163']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_read_data'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '8'}; {'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': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'Read frame: 0x{0}'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'binascii'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hexlify'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '!='}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0x01'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'Response frame does not start with 0x01!'"}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'while_statement', 'children': ['52', '57']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '=='}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0x00'}, {'id': '57', 'type': 'block', 'children': ['58', '62']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '69']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'response'}, {'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': 'RuntimeError'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'Response frame preamble does not contain 0x00FF!'"}, {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '!='}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '0xFF'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'Response frame preamble does not contain 0x00FF!'"}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'augmented_assignment', 'children': ['89', '90'], 'value': '+='}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '98']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '>='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'raise_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'Response contains no data!'"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'frame_len'}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '123']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '122'], 'value': '!='}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '121'], 'value': '&'}, {'id': '113', 'type': 'parenthesized_expression', 'children': ['114']}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'frame_len'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0xFF'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'raise_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'Response length checksum did not match length!'"}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'checksum'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '138', '152']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_uint8_add'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '140', 'type': 'slice', 'children': ['141', '144', '145']}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '144', 'type': 'colon', 'children': []}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '151'], 'value': '+'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '150'], 'value': '+'}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '+'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'frame_len'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '!='}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'checksum'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'raise_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'Response checksum did not match expected value!'"}, {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '166', 'type': 'slice', 'children': ['167', '170', '171']}, {'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '+'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '170', 'type': 'colon', 'children': []}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '+'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'frame_len'} | def _read_frame(self, length):
response = self._read_data(length+8)
logger.debug('Read frame: 0x{0}'.format(binascii.hexlify(response)))
if response[0] != 0x01:
raise RuntimeError('Response frame does not start with 0x01!')
offset = 1
while response[offset] == 0x00:
offset += 1
if offset >= len(response):
raise RuntimeError('Response frame preamble does not contain 0x00FF!')
if response[offset] != 0xFF:
raise RuntimeError('Response frame preamble does not contain 0x00FF!')
offset += 1
if offset >= len(response):
raise RuntimeError('Response contains no data!')
frame_len = response[offset]
if (frame_len + response[offset+1]) & 0xFF != 0:
raise RuntimeError('Response length checksum did not match length!')
checksum = reduce(self._uint8_add, response[offset+2:offset+2+frame_len+1], 0)
if checksum != 0:
raise RuntimeError('Response checksum did not match expected value!')
return response[offset+2:offset+2+frame_len] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'call_function'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'response_length'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'timeout_sec'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '15', 'type': 'block', 'children': ['16', '28', '34', '42', '50', '57', '68', '80', '90', '101', '112', '135']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'bytearray'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'PN532_HOSTTOPN532'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '&'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0xFF'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '49']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '46', 'type': 'slice', 'children': ['47', '48']}, {'id': '47', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '48', 'type': 'colon', 'children': []}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_write_frame'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '65']}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_wait_ready'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'timeout_sec'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_read_data'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'PN532_ACK'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '!='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'PN532_ACK'}; {'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': 'RuntimeError'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'Did not receive expected ACK from PN532!'"}; {'id': '90', 'type': 'if_statement', 'children': ['91', '98']}, {'id': '91', 'type': 'not_operator', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_wait_ready'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'timeout_sec'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_read_frame'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '+'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'response_length'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '129']}, {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'parenthesized_expression', 'children': ['115']}, {'id': '115', 'type': 'boolean_operator', 'children': ['116', '121'], 'value': 'and'}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': '=='}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'PN532_PN532TOHOST'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'parenthesized_expression', 'children': ['126']}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'raise_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'Received unexpected command response!'"}, {'id': '135', 'type': 'return_statement', 'children': ['136']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '138', 'type': 'slice', 'children': ['139', '140']}, {'id': '139', 'type': 'integer', 'children': [], 'value': '2'} | def call_function(self, command, response_length=0, params=[], timeout_sec=1):
data = bytearray(2+len(params))
data[0] = PN532_HOSTTOPN532
data[1] = command & 0xFF
data[2:] = params
self._write_frame(data)
if not self._wait_ready(timeout_sec):
return None
response = self._read_data(len(PN532_ACK))
if response != PN532_ACK:
raise RuntimeError('Did not receive expected ACK from PN532!')
if not self._wait_ready(timeout_sec):
return None
response = self._read_frame(response_length+2)
if not (response[0] == PN532_PN532TOHOST and response[1] == (command+1)):
raise RuntimeError('Received unexpected command response!')
return response[2:] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'createGraph'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'createCollections'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isSmart'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'numberOfShards'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'smartGraphAttribute'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '44', '53', '57', '108', '115', '119', '128', '137', '152', '161', '170', '179', '197', '205', '242']}, {'id': '19', 'type': 'function_definition', 'children': ['20', '21', '23']}; {'id': '20', 'type': 'function_name', 'children': [], 'value': '_checkCollectionList'}, {'id': '21', 'type': 'parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'colName'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '36']}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'COL'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'isCollection'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'colName'}; {'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': 'ValueError'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '%'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"\'%s\' is not a defined Collection"'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'colName'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'graphClass'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'GR'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'getGraphClass'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ed'}; {'id': '56', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'graphClass'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_edgeDefinitions'}; {'id': '62', 'type': 'block', 'children': ['63', '83', '90', '97']}, {'id': '63', 'type': 'if_statement', 'children': ['64', '73']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'COL'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isEdgeCollection'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'edgesCollection'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'raise_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"\'%s\' is not a defined Edge Collection"'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'edgesCollection'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_checkCollectionList'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fromCollections'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_checkCollectionList'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'toCollections'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ed'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'toJson'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_checkCollectionList'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'graphClass'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_orphanedCollections'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '118', 'type': 'dictionary', 'children': []}, {'id': '119', 'type': 'if_statement', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'numberOfShards'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'numberOfShards'"}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'numberOfShards'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'smartGraphAttribute'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'smartGraphAttribute'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'smartGraphAttribute'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '140', 'type': 'dictionary', 'children': ['141', '144', '147']}, {'id': '141', 'type': 'pair', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'pair', 'children': ['145', '146']}, {'id': '145', 'type': 'string', 'children': [], 'value': '"edgeDefinitions"'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ed'}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"orphanCollections"'}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'graphClass'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': '_orphanedCollections'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'isSmart'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'isSmart'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'isSmart'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'options'"}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '182', 'type': 'call', 'children': ['183', '190']}, {'id': '183', 'type': 'attribute', 'children': ['184', '189']}; {'id': '184', 'type': 'attribute', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'graphsURL'}; {'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '204', 'type': 'argument_list', 'children': []}, {'id': '205', 'type': 'if_statement', 'children': ['206', '217', '232']}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '212'], 'value': 'or'}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '211'], 'value': '=='}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '201'}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '216'], 'value': '=='}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '202'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '225']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'graphs'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'graphClass'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"graph"'}; {'id': '232', 'type': 'else_clause', 'children': ['233']}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'raise_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'CreationError'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '241']}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '240', 'type': 'string', 'children': [], 'value': '"errorMessage"'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '242', 'type': 'return_statement', 'children': ['243']}, {'id': '243', 'type': 'subscript', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'graphs'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'name'} | def createGraph(self, name, createCollections = True, isSmart = False, numberOfShards = None, smartGraphAttribute = None) :
def _checkCollectionList(lst) :
for colName in lst :
if not COL.isCollection(colName) :
raise ValueError("'%s' is not a defined Collection" % colName)
graphClass = GR.getGraphClass(name)
ed = []
for e in graphClass._edgeDefinitions :
if not COL.isEdgeCollection(e.edgesCollection) :
raise ValueError("'%s' is not a defined Edge Collection" % e.edgesCollection)
_checkCollectionList(e.fromCollections)
_checkCollectionList(e.toCollections)
ed.append(e.toJson())
_checkCollectionList(graphClass._orphanedCollections)
options = {}
if numberOfShards:
options['numberOfShards'] = numberOfShards
if smartGraphAttribute:
options['smartGraphAttribute'] = smartGraphAttribute
payload = {
"name": name,
"edgeDefinitions": ed,
"orphanCollections": graphClass._orphanedCollections
}
if isSmart :
payload['isSmart'] = isSmart
if options:
payload['options'] = options
payload = json.dumps(payload)
r = self.connection.session.post(self.graphsURL, data = payload)
data = r.json()
if r.status_code == 201 or r.status_code == 202 :
self.graphs[name] = graphClass(self, data["graph"])
else :
raise CreationError(data["errorMessage"], data)
return self.graphs[name] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_v2_event_into_v1'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '15', '260']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Helper method to convert Sensu 2.x event into Sensu 1.x event.\n '''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"v2_event_mapped_into_v1"'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '30']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '27'], 'value': 'and'}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'client'"}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"entity"'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '30', 'type': 'block', 'children': ['31', '39', '58', '77', '96', '115', '128', '149', '182', '254']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'entity'"}, {'id': '39', 'type': 'if_statement', 'children': ['40', '45']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'not'}, {'id': '41', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'client'"}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'entity'"}, {'id': '57', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '58', 'type': 'if_statement', 'children': ['59', '64']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'not'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"subscribers"'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'client'"}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '72']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'client'"}, {'id': '71', 'type': 'string', 'children': [], 'value': "'subscribers'"}; {'id': '72', 'type': 'subscript', 'children': ['73', '76']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'entity'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'subscriptions'"}, {'id': '77', 'type': 'if_statement', 'children': ['78', '83']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"subscribers"'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'check'"}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '90', 'type': 'string', 'children': [], 'value': "'subscribers'"}, {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'check'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "'subscriptions'"}; {'id': '96', 'type': 'if_statement', 'children': ['97', '102']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'not'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"source"'}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '110']}, {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'check'"}, {'id': '109', 'type': 'string', 'children': [], 'value': "'source'"}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '114', 'type': 'string', 'children': [], 'value': "'proxy_entity_id'"}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'action_state_mapping'}; {'id': '118', 'type': 'dictionary', 'children': ['119', '122', '125']}, {'id': '119', 'type': 'pair', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'flapping'"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'flapping'"}; {'id': '122', 'type': 'pair', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'passing'"}; {'id': '124', 'type': 'string', 'children': [], 'value': "'resolve'"}, {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'failing'"}, {'id': '127', 'type': 'string', 'children': [], 'value': "'create'"}; {'id': '128', 'type': 'if_statement', 'children': ['129', '134', '143']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'in'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"state"'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'check'"}; {'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': 'state'}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '142', 'type': 'string', 'children': [], 'value': "'state'"}, {'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': 'state'}; {'id': '148', 'type': 'string', 'children': [], 'value': '"unknown::2.0_event"'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '161', '174']}; {'id': '150', 'type': 'boolean_operator', 'children': ['151', '154'], 'value': 'and'}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'not'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"action"'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '160'], 'value': 'in'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'action_state_mapping'}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '167']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'action'"}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'action_state_mapping'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'else_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'action'"}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '188']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'in'}; {'id': '184', 'type': 'string', 'children': [], 'value': '"history"'}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '188', 'type': 'block', 'children': ['189', '204', '208', '246']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '196']}, {'id': '191', 'type': 'subscript', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'check'"}, {'id': '195', 'type': 'string', 'children': [], 'value': "'history_v2'"}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'subscript', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'check'"}, {'id': '203', 'type': 'string', 'children': [], 'value': "'history'"}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'legacy_history'}, {'id': '207', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '208', 'type': 'for_statement', 'children': ['209', '210', '215']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '214', 'type': 'string', 'children': [], 'value': "'history'"}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'if_statement', 'children': ['217', '224', '237']}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'status'"}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'legacy_history'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'status'"}, {'id': '237', 'type': 'else_clause', 'children': ['238']}; {'id': '238', 'type': 'block', 'children': ['239']}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'legacy_history'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'string', 'children': [], 'value': '"3"'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '253']}; {'id': '248', 'type': 'subscript', 'children': ['249', '252']}, {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '251', 'type': 'string', 'children': [], 'value': "'check'"}; {'id': '252', 'type': 'string', 'children': [], 'value': "'history'"}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'legacy_history'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '259']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'v2_event_mapped_into_v1'"}, {'id': '259', 'type': 'True', 'children': []}; {'id': '260', 'type': 'return_statement', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'event'} | def map_v2_event_into_v1(event):
'''
Helper method to convert Sensu 2.x event into Sensu 1.x event.
'''
if "v2_event_mapped_into_v1" in event:
return event
if not bool(event.get('client')) and "entity" in event:
event['client'] = event['entity']
if "name" not in event['client']:
event['client']['name'] = event['entity']['id']
if "subscribers" not in event['client']:
event['client']['subscribers'] = event['entity']['subscriptions']
if "subscribers" not in event['check']:
event['check']['subscribers'] = event['check']['subscriptions']
if "source" not in event['check']:
event['check']['source'] = event['check']['proxy_entity_id']
action_state_mapping = {'flapping': 'flapping', 'passing': 'resolve',
'failing': 'create'}
if "state" in event['check']:
state = event['check']['state']
else:
state = "unknown::2.0_event"
if "action" not in event and state.lower() in action_state_mapping:
event['action'] = action_state_mapping[state.lower()]
else:
event['action'] = state
if "history" in event['check']:
event['check']['history_v2'] = deepcopy(event['check']['history'])
legacy_history = []
for history in event['check']['history']:
if isinstance(history['status'], int):
legacy_history.append(str(history['status']))
else:
legacy_history.append("3")
event['check']['history'] = legacy_history
event['v2_event_mapped_into_v1'] = True
return event |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gen_df_site'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_csv_in'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'list_table'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'url_base'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'url_repo_input_site'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '14', 'type': 'block', 'children': ['15', '17', '27']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'''Generate description info of supy output results as a dataframe\n Parameters\n ----------\n path_csv_out : str, optional\n path to the output csv file (the default is 'df_output.csv')\n list_csv_in : list, optional\n list of file names for csv files with meta info (the default is url_repo_input_site, which is defined at the top of this file)\n url_base : URL, optional\n URL to the input dir of repo base (the default is url_repo_input, which is defined at the top of this file)\n Returns\n -------\n pd.DataFrame\n full path to the output csv file\n '''"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'list_url_table'}; {'id': '20', 'type': 'list_comprehension', 'children': ['21', '24']}, {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '/'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'url_base'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'list_csv_in'}, {'id': '27', 'type': 'try_statement', 'children': ['28', '47', '68']}; {'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': 'df_var_info'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '44']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'read_csv'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list_url_table'}, {'id': '47', 'type': 'except_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'list_url_table'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'if_statement', 'children': ['54', '62']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '61']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "f'{url} not existing!'"}; {'id': '68', 'type': 'else_clause', 'children': ['69']}, {'id': '69', 'type': 'block', 'children': ['70', '91', '113', '128', '142', '181', '212', '238', '245', '263', '281']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'df_var_info_x'}, {'id': '73', 'type': 'call', 'children': ['74', '89']}; {'id': '74', 'type': 'attribute', 'children': ['75', '87', '88']}, {'id': '75', 'type': 'call', 'children': ['76', '80']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'df_var_info'}; {'id': '78', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'drop'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '84']}, {'id': '81', 'type': 'list', 'children': ['82', '83'], 'value': "['No.', 'Use']"}; {'id': '82', 'type': 'string', 'children': [], 'value': "'No.'"}, {'id': '83', 'type': 'string', 'children': [], 'value': "'Use'"}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'set_index'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'Column Name'"}, {'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': 'df_var_info_x'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '96', 'type': 'call', 'children': ['97', '102']}, {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'df_var_info_x'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'lambda', 'children': ['104', '106']}; {'id': '104', 'type': 'lambda_parameters', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'`'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "''"}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dict_var_full'}; {'id': '116', 'type': 'call', 'children': ['117', '122']}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sp'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'supy_load'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'exp_dict_full'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sp'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'supy_load'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'dict_var2SiteSelect'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'dict_var_ref_suews'}, {'id': '131', 'type': 'dictionary_comprehension', 'children': ['132', '139']}; {'id': '132', 'type': 'pair', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'extract_var_suews'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dict_var_full'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'dict_var_full'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'df_var_ref_suews'}, {'id': '145', 'type': 'call', 'children': ['146', '173']}; {'id': '146', 'type': 'attribute', 'children': ['147', '172']}, {'id': '147', 'type': 'attribute', 'children': ['148', '171']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '167']}, {'id': '153', 'type': 'dictionary_comprehension', 'children': ['154', '164']}; {'id': '154', 'type': 'pair', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dict_var_ref_suews'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dict_var_ref_suews'}, {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '169', 'type': 'list', 'children': ['170'], 'value': '[0]'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'rename'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '178']}; {'id': '174', 'type': 'dictionary', 'children': ['175']}, {'id': '175', 'type': 'pair', 'children': ['176', '177']}; {'id': '176', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'SUEWS-related variables'"}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'dict_var_desc'}; {'id': '184', 'type': 'dictionary_comprehension', 'children': ['185', '203']}, {'id': '185', 'type': 'pair', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '202']}, {'id': '193', 'type': 'attribute', 'children': ['194', '201']}; {'id': '194', 'type': 'attribute', 'children': ['195', '200']}, {'id': '195', 'type': 'subscript', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'df_var_info_x'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'loc'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '202', 'type': 'argument_list', 'children': []}, {'id': '203', 'type': 'for_in_clause', 'children': ['204', '207']}; {'id': '204', 'type': 'pattern_list', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'dict_var_ref_suews'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'df_var_desc'}, {'id': '215', 'type': 'call', 'children': ['216', '231']}; {'id': '216', 'type': 'attribute', 'children': ['217', '229', '230']}, {'id': '217', 'type': 'attribute', 'children': ['218', '228']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'dict_var_desc'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '226', 'type': 'list', 'children': ['227'], 'value': '[0]'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '229', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'rename'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '234', 'type': 'dictionary', 'children': ['235']}, {'id': '235', 'type': 'pair', 'children': ['236', '237']}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'string', 'children': [], 'value': "'Description'"}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'df_var_dim'}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'gen_df_dim'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'df_init_sample'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'df_var_site_raw'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '257', '260']}, {'id': '253', 'type': 'list', 'children': ['254', '255', '256'], 'value': '[df_var_dim, df_var_desc, df_var_ref_suews]'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'df_var_dim'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'df_var_desc'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'df_var_ref_suews'}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '262', 'type': 'False', 'children': []}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'df_var_site'}; {'id': '266', 'type': 'call', 'children': ['267', '280']}, {'id': '267', 'type': 'attribute', 'children': ['268', '279']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'df_var_site_raw'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '276']}, {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'set_input'}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '278', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'dropna'}; {'id': '280', 'type': 'argument_list', 'children': []}, {'id': '281', 'type': 'return_statement', 'children': ['282']} | def gen_df_site(
list_csv_in=list_table,
url_base=url_repo_input_site)->pd.DataFrame:
'''Generate description info of supy output results as a dataframe
Parameters
----------
path_csv_out : str, optional
path to the output csv file (the default is 'df_output.csv')
list_csv_in : list, optional
list of file names for csv files with meta info (the default is url_repo_input_site, which is defined at the top of this file)
url_base : URL, optional
URL to the input dir of repo base (the default is url_repo_input, which is defined at the top of this file)
Returns
-------
pd.DataFrame
full path to the output csv file
'''
list_url_table = [
url_base/table for table in list_csv_in
]
try:
df_var_info = pd.concat([pd.read_csv(f) for f in list_url_table])
except:
for url in list_url_table:
if not url.get().ok:
print(f'{url} not existing!')
else:
df_var_info_x = df_var_info\
.drop(['No.', 'Use'], axis=1)\
.set_index('Column Name')
df_var_info_x.index = df_var_info_x.index.map(
lambda x: x.replace('`', ''))
dict_var_full = sp.supy_load.exp_dict_full(
sp.supy_load.dict_var2SiteSelect)
dict_var_ref_suews = {
k: extract_var_suews(dict_var_full, k)
for k in dict_var_full
}
df_var_ref_suews = pd.DataFrame(
{k: ', '.join(dict_var_ref_suews[k])
for k in dict_var_ref_suews},
index=[0]).T.rename({
0: 'SUEWS-related variables'
}, axis=1)
dict_var_desc = {
k: '\n'.join(df_var_info_x.loc[v].values.flatten())
for k, v in dict_var_ref_suews.items()
}
df_var_desc = pd.DataFrame(dict_var_desc, index=[0]).T\
.rename(columns={0: 'Description'})
df_var_dim = gen_df_dim(df_init_sample)
df_var_site_raw = pd.concat(
[df_var_dim, df_var_desc, df_var_ref_suews],
axis=1, sort=False)
df_var_site = df_var_site_raw.filter(items=set_input, axis=0).dropna()
return df_var_site |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_for_tasks_to_complete'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'batch_service_client'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'job_ids'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '7', 'type': 'block', 'children': ['8', '20', '33', '118']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'timeout_expiration'}, {'id': '11', 'type': 'binary_operator', 'children': ['12', '19'], 'value': '+'}; {'id': '12', 'type': 'call', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '30']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"Monitoring all tasks for \'Completed\' state, timeout in {}..."'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '32', 'type': 'string', 'children': [], 'value': "''"}, {'id': '33', 'type': 'while_statement', 'children': ['34', '43']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '42'], 'value': '<'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'timeout_expiration'}, {'id': '43', 'type': 'block', 'children': ['44', '52', '60', '99']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '51', 'type': 'string', 'children': [], 'value': "''"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'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': 'sys'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'for_statement', 'children': ['61', '64', '65']}, {'id': '61', 'type': 'tuple_pattern', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'job_id'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'job_ids'}, {'id': '65', 'type': 'block', 'children': ['66', '77', '95']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tasks'}, {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'batch_service_client'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'job_id'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'incomplete_tasks'}; {'id': '80', 'type': 'list_comprehension', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tasks'}, {'id': '85', 'type': 'if_clause', 'children': ['86']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '!='}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'batchmodels'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'TaskState'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'completed'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'incomplete_tasks'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'break_statement', 'children': []}, {'id': '99', 'type': 'if_statement', 'children': ['100', '102', '109']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'incomplete_tasks'}; {'id': '102', 'type': 'block', 'children': ['103', '107']}, {'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': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'True', 'children': []}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'raise_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '+'}, {'id': '123', 'type': 'concatenated_string', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"ERROR: Tasks did not reach \'Completed\' state within "'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"timeout period of "'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'timeout'} | def wait_for_tasks_to_complete(batch_service_client, job_ids, timeout):
timeout_expiration = datetime.datetime.now() + timeout
print("Monitoring all tasks for 'Completed' state, timeout in {}...".format(timeout), end='')
while datetime.datetime.now() < timeout_expiration:
print('.', end='')
sys.stdout.flush()
for (job_id, _) in job_ids:
tasks = batch_service_client.task.list(job_id)
incomplete_tasks = [task for task in tasks if
task.state != batchmodels.TaskState.completed]
if incomplete_tasks:
break
if not incomplete_tasks:
print()
return True
else:
time.sleep(1)
raise RuntimeError("ERROR: Tasks did not reach 'Completed' state within "
"timeout period of " + str(timeout)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '52']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_world_with_elegans'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '39', '46', '49']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'radius'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '350'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '350'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'wireframe'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'species_list'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'camera_position'}; {'id': '34', 'type': 'tuple', 'children': ['35', '37', '38']}, {'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '22'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '32'}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'camera_rotation'}, {'id': '41', 'type': 'tuple', 'children': ['42', '44', '45']}; {'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'}, {'id': '43', 'type': 'float', 'children': [], 'value': '0.6'}; {'id': '44', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '45', 'type': 'float', 'children': [], 'value': '0.6'}; {'id': '46', 'type': 'default_parameter', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'return_id'}; {'id': '48', 'type': 'False', 'children': []}, {'id': '49', 'type': 'default_parameter', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'predicator'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53', '59', '68', '75', '89', '100', '109', '113', '155', '218', '249', '260', '275', '328']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '58'], 'value': 'or'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '58', 'type': 'dictionary', 'children': []}, {'id': '59', 'type': 'import_from_statement', 'children': ['60', '64', '66']}; {'id': '60', 'type': 'dotted_name', 'children': ['61', '62', '63']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'IPython'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'core'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'display'}; {'id': '64', 'type': 'dotted_name', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'display'}; {'id': '66', 'type': 'dotted_name', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'HTML'}; {'id': '68', 'type': 'import_from_statement', 'children': ['69', '73']}, {'id': '69', 'type': 'relative_import', 'children': ['70', '71']}; {'id': '70', 'type': 'import_prefix', 'children': []}, {'id': '71', 'type': 'dotted_name', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '73', 'type': 'dotted_name', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'load_world'}, {'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': 'world'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'str'}, {'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': 'world'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'load_world'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '__parse_world'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97', '98', '99']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'world'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'radius'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'species_list'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'predicator'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'color_scale'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'default_color_scale'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'plots'}; {'id': '112', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '113', 'type': 'for_statement', 'children': ['114', '115', '116']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'species_info'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'plots'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'dictionary', 'children': ['124', '127', '132']}; {'id': '124', 'type': 'pair', 'children': ['125', '126']}, {'id': '125', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '126', 'type': 'string', 'children': [], 'value': "'Particles'"}, {'id': '127', 'type': 'pair', 'children': ['128', '129']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'species_info'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '132', 'type': 'pair', 'children': ['133', '134']}, {'id': '133', 'type': 'string', 'children': [], 'value': "'options'"}; {'id': '134', 'type': 'dictionary', 'children': ['135', '140', '150']}, {'id': '135', 'type': 'pair', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'species_info'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '140', 'type': 'pair', 'children': ['141', '142']}, {'id': '141', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'color_scale'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'get_color'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'species_info'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '150', 'type': 'pair', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'size'"}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'species_info'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'size'"}, {'id': '155', 'type': 'if_statement', 'children': ['156', '159']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '158', 'type': 'None', 'children': []}, {'id': '159', 'type': 'block', 'children': ['160', '179', '202']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '163', 'type': 'dictionary', 'children': ['164', '167', '170', '173', '176']}; {'id': '164', 'type': 'pair', 'children': ['165', '166']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '166', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '167', 'type': 'pair', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '169', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '170', 'type': 'pair', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '172', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '173', 'type': 'pair', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'z'"}, {'id': '175', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '176', 'type': 'pair', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': "'options'"}; {'id': '178', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '179', 'type': 'for_statement', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'for_statement', 'children': ['184', '187', '192']}; {'id': '184', 'type': 'pattern_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '200']}, {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'plots'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'dictionary', 'children': ['209', '212', '215']}, {'id': '209', 'type': 'pair', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '211', 'type': 'string', 'children': [], 'value': "'DebugObject'"}; {'id': '212', 'type': 'pair', 'children': ['213', '214']}, {'id': '213', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '215', 'type': 'pair', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': "'options'"}, {'id': '217', 'type': 'dictionary', 'children': []}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '221', 'type': 'dictionary', 'children': ['222', '225']}; {'id': '222', 'type': 'pair', 'children': ['223', '224']}, {'id': '223', 'type': 'string', 'children': [], 'value': "'plots'"}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'plots'}, {'id': '225', 'type': 'pair', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'options'"}, {'id': '227', 'type': 'dictionary', 'children': ['228', '231', '234', '240', '243', '246']}; {'id': '228', 'type': 'pair', 'children': ['229', '230']}, {'id': '229', 'type': 'string', 'children': [], 'value': "'world_width'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'width'}, {'id': '231', 'type': 'pair', 'children': ['232', '233']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'world_height'"}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '234', 'type': 'pair', 'children': ['235', '236']}, {'id': '235', 'type': 'string', 'children': [], 'value': "'range'"}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': '__get_range_of_world'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'world'}; {'id': '240', 'type': 'pair', 'children': ['241', '242']}, {'id': '241', 'type': 'string', 'children': [], 'value': "'autorange'"}; {'id': '242', 'type': 'False', 'children': []}, {'id': '243', 'type': 'pair', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'grid'"}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '246', 'type': 'pair', 'children': ['247', '248']}, {'id': '247', 'type': 'string', 'children': [], 'value': "'save_image'"}; {'id': '248', 'type': 'True', 'children': []}, {'id': '249', 'type': 'if_statement', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'wireframe'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '259']}; {'id': '254', 'type': 'subscript', 'children': ['255', '258']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'options'"}; {'id': '258', 'type': 'string', 'children': [], 'value': "'space_mode'"}, {'id': '259', 'type': 'string', 'children': [], 'value': "'wireframe'"}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'model_id'}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '274'], 'value': '+'}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '+'}, {'id': '265', 'type': 'string', 'children': [], 'value': '\'"viz\''}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'uuid4'}, {'id': '273', 'type': 'argument_list', 'children': []}; {'id': '274', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'display'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'HTML'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'generate_html'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '327']}, {'id': '285', 'type': 'dictionary', 'children': ['286', '294', '297', '302', '307', '312', '317', '322']}; {'id': '286', 'type': 'pair', 'children': ['287', '288']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'model'"}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '294', 'type': 'pair', 'children': ['295', '296']}, {'id': '295', 'type': 'string', 'children': [], 'value': "'model_id'"}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'model_id'}, {'id': '297', 'type': 'pair', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': "'px'"}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'camera_position'}, {'id': '301', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '302', 'type': 'pair', 'children': ['303', '304']}, {'id': '303', 'type': 'string', 'children': [], 'value': "'py'"}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'camera_position'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '307', 'type': 'pair', 'children': ['308', '309']}; {'id': '308', 'type': 'string', 'children': [], 'value': "'pz'"}, {'id': '309', 'type': 'subscript', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'camera_position'}, {'id': '311', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '312', 'type': 'pair', 'children': ['313', '314']}, {'id': '313', 'type': 'string', 'children': [], 'value': "'rx'"}; {'id': '314', 'type': 'subscript', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'camera_rotation'}; {'id': '316', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '317', 'type': 'pair', 'children': ['318', '319']}; {'id': '318', 'type': 'string', 'children': [], 'value': "'ry'"}, {'id': '319', 'type': 'subscript', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'camera_rotation'}, {'id': '321', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '322', 'type': 'pair', 'children': ['323', '324']}, {'id': '323', 'type': 'string', 'children': [], 'value': "'rz'"}; {'id': '324', 'type': 'subscript', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'camera_rotation'}; {'id': '326', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '327', 'type': 'string', 'children': [], 'value': "'templates/particles.tmpl'"}; {'id': '328', 'type': 'if_statement', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'return_id'}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'return_statement', 'children': ['332']} | def plot_world_with_elegans(
world, radius=None, width=350, height=350, config=None, grid=True,
wireframe=False, species_list=None, debug=None, max_count=1000,
camera_position=(-22, 23, 32), camera_rotation=(-0.6, 0.5, 0.6),
return_id=False, predicator=None):
config = config or {}
from IPython.core.display import display, HTML
from .simulation import load_world
if isinstance(world, str):
world = load_world(world)
species = __parse_world(world, radius, species_list, max_count, predicator)
color_scale = default_color_scale(config=config)
plots = []
for species_info in species:
plots.append({
'type': 'Particles',
'data': species_info['data'],
'options': {
'name': species_info['name'],
'color': color_scale.get_color(species_info['name']),
'size': species_info['size']
}
})
if debug is not None:
data = {'type': [], 'x': [], 'y': [], 'z': [], 'options': []}
for obj in debug:
for k, v in obj.items():
data[k].append(v)
plots.append({
'type': 'DebugObject',
'data': data,
'options': {}
})
model = {
'plots': plots,
'options': {
'world_width': width,
'world_height': height,
'range': __get_range_of_world(world),
'autorange': False,
'grid': grid,
'save_image': True
}
}
if wireframe:
model['options']['space_mode'] = 'wireframe'
model_id = '"viz' + str(uuid.uuid4()) + '"'
display(HTML(generate_html(
{'model': json.dumps(model), 'model_id': model_id,
'px': camera_position[0], 'py': camera_position[1], 'pz': camera_position[2],
'rx': camera_rotation[0], 'ry': camera_rotation[1], 'rz': camera_rotation[2]},
'templates/particles.tmpl')))
if return_id:
return model_id |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_trajectory2d_with_matplotlib'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'xy'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'wireframe'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '22', 'type': 'True', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'noaxis'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'plot_range'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'dictionary_splat_pattern', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '31', 'type': 'block', 'children': ['32', '38', '46', '85', '104', '123', '131', '153', '161', '174', '188', '201', '214', '227', '231', '281', '289', '330']}; {'id': '32', 'type': 'import_statement', 'children': ['33']}, {'id': '33', 'type': 'aliased_import', 'children': ['34', '37']}; {'id': '34', 'type': 'dotted_name', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'matplotlib'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pyplot'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '71']}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '63'], 'value': 'or'}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '55'], 'value': 'or'}, {'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': 'plane'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': 'not'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'tuple', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '61', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '62', 'type': 'string', 'children': [], 'value': "'z'"}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': 'not'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'tuple', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '69', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '70', 'type': 'string', 'children': [], 'value': "'z'"}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'raise_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"invalid \'plane\' argument [{}] was given."'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'xidx'}; {'id': '88', 'type': 'conditional_expression', 'children': ['89', '90', '95'], 'value': 'if'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '=='}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '95', 'type': 'parenthesized_expression', 'children': ['96']}; {'id': '96', 'type': 'conditional_expression', 'children': ['97', '98', '103'], 'value': 'if'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': '=='}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '103', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'yidx'}, {'id': '107', 'type': 'conditional_expression', 'children': ['108', '109', '114'], 'value': 'if'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '114', 'type': 'parenthesized_expression', 'children': ['115']}, {'id': '115', 'type': 'conditional_expression', 'children': ['116', '117', '122'], 'value': 'if'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '=='}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '122', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '130', 'type': 'argument_list', 'children': []}, {'id': '131', 'type': 'if_statement', 'children': ['132', '142']}; {'id': '132', 'type': 'boolean_operator', 'children': ['133', '136'], 'value': 'and'}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '>'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'sample'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '__get_range_of_trajectories'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'plot_range'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '164', 'type': 'tuple', 'children': ['165', '168', '171']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'z'"}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '177', 'type': 'dictionary', 'children': ['178', '183']}; {'id': '178', 'type': 'pair', 'children': ['179', '180']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'xidx'}, {'id': '183', 'type': 'pair', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'yidx'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '193']}; {'id': '190', 'type': 'pattern_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': '__prepare_plot_with_matplotlib'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198', '199', '200']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'figsize'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'wireframe'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'noaxis'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '226']}, {'id': '221', 'type': 'attribute', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '226', 'type': 'argument_list', 'children': []}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '230', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '231', 'type': 'for_statement', 'children': ['232', '235', '239']}; {'id': '232', 'type': 'pattern_list', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '239', 'type': 'block', 'children': ['240', '250', '272']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '246']}; {'id': '242', 'type': 'pattern_list', 'children': ['243', '244', '245']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'xarr'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'yarr'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'zarr'}; {'id': '246', 'type': 'expression_list', 'children': ['247', '248', '249']}, {'id': '247', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '248', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '249', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '250', 'type': 'for_statement', 'children': ['251', '252', '253']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '253', 'type': 'block', 'children': ['254', '263']}; {'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': 'xarr'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'xidx'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'yarr'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'yidx'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'tuple', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'xarr'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'yarr'}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': '__plot_trajectory2d_with_matplotlib'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286', '287']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '287', 'type': 'dictionary_splat', 'children': ['288']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '289', 'type': 'if_statement', 'children': ['290', '297']}; {'id': '290', 'type': 'boolean_operator', 'children': ['291', '294'], 'value': 'and'}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': 'is'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '293', 'type': 'None', 'children': []}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': 'is'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '296', 'type': 'False', 'children': []}, {'id': '297', 'type': 'block', 'children': ['298', '308', '322']}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'assignment', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'legend_opts'}, {'id': '301', 'type': 'dictionary', 'children': ['302', '305']}; {'id': '302', 'type': 'pair', 'children': ['303', '304']}, {'id': '303', 'type': 'string', 'children': [], 'value': '"loc"'}; {'id': '304', 'type': 'string', 'children': [], 'value': '"best"'}, {'id': '305', 'type': 'pair', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': '"shadow"'}, {'id': '307', 'type': 'True', 'children': []}; {'id': '308', 'type': 'if_statement', 'children': ['309', '314']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '311', 'type': 'argument_list', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'legend_opts'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'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': 'ax'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'dictionary_splat', 'children': ['329']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'legend_opts'}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'show'}, {'id': '335', 'type': 'argument_list', 'children': []} | def plot_trajectory2d_with_matplotlib(
obs, plane='xy', max_count=10, figsize=6, legend=True,
wireframe=False, grid=True, noaxis=False, plot_range=None, **kwargs):
import matplotlib.pyplot as plt
plane = plane.lower()
if len(plane) != 2 or plane[0] not in ('x', 'y', 'z') or plane[1] not in ('x', 'y', 'z'):
raise ValueError("invalid 'plane' argument [{}] was given.".format(repr(plane)))
xidx = 0 if plane[0] == 'x' else (1 if plane[0] == 'y' else 2)
yidx = 0 if plane[1] == 'x' else (1 if plane[1] == 'y' else 2)
data = obs.data()
if max_count is not None and len(data) > max_count:
data = random.sample(data, max_count)
wrange = __get_range_of_trajectories(data, plot_range)
wrange = (wrange['x'], wrange['y'], wrange['z'])
wrange = {'x': wrange[xidx], 'y': wrange[yidx]}
fig, ax = __prepare_plot_with_matplotlib(
wrange, figsize, grid, wireframe, noaxis)
ax.set_xlabel(plane[0].upper())
ax.set_ylabel(plane[1].upper())
lines = []
for i, y in enumerate(data):
xarr, yarr, zarr = [], [], []
for pos in y:
xarr.append(pos[xidx])
yarr.append(pos[yidx])
lines.append((xarr, yarr))
__plot_trajectory2d_with_matplotlib(lines, ax, **kwargs)
if legend is not None and legend is not False:
legend_opts = {"loc": "best", "shadow": True}
if isinstance(legend, dict):
legend_opts.update(legend)
ax.legend(**legend_opts)
plt.show() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '40']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_world2d_with_matplotlib'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'xy'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'marker_size'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'wireframe'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'species_list'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'max_count'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'angle'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'noaxis'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'scale'}, {'id': '37', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '38', 'type': 'dictionary_splat_pattern', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'block', 'children': ['41', '47', '55', '94', '113', '132', '174', '182', '195', '209', '222', '241', '254', '267', '322']}, {'id': '41', 'type': 'import_statement', 'children': ['42']}; {'id': '42', 'type': 'aliased_import', 'children': ['43', '46']}, {'id': '43', 'type': 'dotted_name', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'matplotlib'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pyplot'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'if_statement', 'children': ['56', '80']}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '72'], 'value': 'or'}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '64'], 'value': 'or'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '63'], 'value': '!='}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': 'not'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'tuple', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '70', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '71', 'type': 'string', 'children': [], 'value': "'z'"}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': 'not'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'tuple', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'z'"}; {'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': 'ValueError'}; {'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': '"invalid \'plane\' argument [{}] was given."'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'xidx'}, {'id': '97', 'type': 'conditional_expression', 'children': ['98', '99', '104'], 'value': 'if'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '=='}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '104', 'type': 'parenthesized_expression', 'children': ['105']}, {'id': '105', 'type': 'conditional_expression', 'children': ['106', '107', '112'], 'value': 'if'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '112', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'yidx'}; {'id': '116', 'type': 'conditional_expression', 'children': ['117', '118', '123'], 'value': 'if'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': '=='}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124']}; {'id': '124', 'type': 'conditional_expression', 'children': ['125', '126', '131'], 'value': 'if'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '131', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'species_list'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137', '159']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'species_list'}; {'id': '140', 'type': 'list_comprehension', 'children': ['141', '150']}, {'id': '141', 'type': 'call', 'children': ['142', '149']}; {'id': '142', 'type': 'attribute', 'children': ['143', '148']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'species'}, {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'serial'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'for_in_clause', 'children': ['151', '154']}, {'id': '151', 'type': 'pattern_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'list_particles'}; {'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': 'species_list'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '169']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'species_list'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'species_list'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '__get_range_of_world'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'scale'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '185', 'type': 'tuple', 'children': ['186', '189', '192']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'z'"}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '198', 'type': 'dictionary', 'children': ['199', '204']}, {'id': '199', 'type': 'pair', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'wrange'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'xidx'}; {'id': '204', 'type': 'pair', 'children': ['205', '206']}, {'id': '205', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'yidx'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}, {'id': '211', 'type': 'pattern_list', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': '__prepare_plot_with_matplotlib'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219', '220', '221']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'wrange'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'wireframe'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'noaxis'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'pattern_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'scatters'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'plots'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': '__scatter_world2d_with_matplotlib'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231', '234', '235', '236', '237', '238', '239']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'world'}, {'id': '231', 'type': 'tuple', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'xidx'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'yidx'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'species_list'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'marker_size'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'max_count'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'scale'}, {'id': '239', 'type': 'dictionary_splat', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'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': 'ax'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}, {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'plane'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '253', 'type': 'argument_list', 'children': []}; {'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': 'ax'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '266']}, {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'plane'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '266', 'type': 'argument_list', 'children': []}, {'id': '267', 'type': 'if_statement', 'children': ['268', '275']}; {'id': '268', 'type': 'boolean_operator', 'children': ['269', '272'], 'value': 'and'}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': 'is'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '271', 'type': 'None', 'children': []}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': 'is'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '274', 'type': 'False', 'children': []}, {'id': '275', 'type': 'block', 'children': ['276', '300', '314']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'legend_opts'}, {'id': '279', 'type': 'dictionary', 'children': ['280', '283', '288', '291', '294', '297']}; {'id': '280', 'type': 'pair', 'children': ['281', '282']}, {'id': '281', 'type': 'string', 'children': [], 'value': "'loc'"}; {'id': '282', 'type': 'string', 'children': [], 'value': "'center left'"}, {'id': '283', 'type': 'pair', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'bbox_to_anchor'"}, {'id': '285', 'type': 'tuple', 'children': ['286', '287']}; {'id': '286', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '287', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '288', 'type': 'pair', 'children': ['289', '290']}, {'id': '289', 'type': 'string', 'children': [], 'value': "'shadow'"}; {'id': '290', 'type': 'False', 'children': []}, {'id': '291', 'type': 'pair', 'children': ['292', '293']}; {'id': '292', 'type': 'string', 'children': [], 'value': "'frameon'"}, {'id': '293', 'type': 'False', 'children': []}; {'id': '294', 'type': 'pair', 'children': ['295', '296']}, {'id': '295', 'type': 'string', 'children': [], 'value': "'fontsize'"}; {'id': '296', 'type': 'string', 'children': [], 'value': "'x-large'"}, {'id': '297', 'type': 'pair', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': "'scatterpoints'"}, {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'if_statement', 'children': ['301', '306']}, {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '303', 'type': 'argument_list', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'legend_opts'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'legend'}, {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'dictionary_splat', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'legend_opts'}; {'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': 'plt'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'show'}, {'id': '327', 'type': 'argument_list', 'children': []} | def plot_world2d_with_matplotlib(
world, plane='xy', marker_size=3, figsize=6, grid=True,
wireframe=False, species_list=None, max_count=1000, angle=None,
legend=True, noaxis=False, scale=1.0, **kwargs):
import matplotlib.pyplot as plt
plane = plane.lower()
if len(plane) != 2 or plane[0] not in ('x', 'y', 'z') or plane[1] not in ('x', 'y', 'z'):
raise ValueError("invalid 'plane' argument [{}] was given.".format(repr(plane)))
xidx = 0 if plane[0] == 'x' else (1 if plane[0] == 'y' else 2)
yidx = 0 if plane[1] == 'x' else (1 if plane[1] == 'y' else 2)
if species_list is None:
species_list = [p.species().serial() for pid, p in world.list_particles()]
species_list = sorted(
set(species_list), key=species_list.index)
wrange = __get_range_of_world(world, scale)
wrange = (wrange['x'], wrange['y'], wrange['z'])
wrange = {'x': wrange[xidx], 'y': wrange[yidx]}
fig, ax = __prepare_plot_with_matplotlib(
wrange, figsize, grid, wireframe, noaxis)
scatters, plots = __scatter_world2d_with_matplotlib(
world, (xidx, yidx), ax, species_list, marker_size, max_count, scale, **kwargs)
ax.set_xlabel(plane[0].upper())
ax.set_ylabel(plane[1].upper())
if legend is not None and legend is not False:
legend_opts = {'loc': 'center left', 'bbox_to_anchor': (1.0, 0.5),
'shadow': False, 'frameon': False, 'fontsize': 'x-large',
'scatterpoints': 1}
if isinstance(legend, dict):
legend_opts.update(legend)
ax.legend(**legend_opts)
plt.show() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_model'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'is_netfree'}; {'id': '6', 'type': 'False', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'without_reset'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'seeds'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'effective'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '120']}, {'id': '17', 'type': 'try_statement', 'children': ['18', '108']}; {'id': '18', 'type': 'block', 'children': ['19', '48', '59', '70', '78', '90']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '25', '36']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'or'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'seeds'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_netfree'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ecell4_base'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'NetfreeModel'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'}, {'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': 'ecell4_base'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'NetworkModel'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sp'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'SPECIES_ATTRIBUTES'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'add_species_attribute'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sp'}, {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'rr'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'REACTION_RULES'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'add_reaction_rule'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'rr'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '73']}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'without_reset'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'reset_model'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'seeds'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'expand'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'seeds'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '100']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ecell4_base'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'core'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'NetfreeModel'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'set_effective'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'effective'}; {'id': '108', 'type': 'except_clause', 'children': ['109', '113']}, {'id': '109', 'type': 'as_pattern', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '111', 'type': 'as_pattern_target', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '113', 'type': 'block', 'children': ['114', '118']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'reset_model'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'raise_statement', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'm'} | def get_model(is_netfree=False, without_reset=False, seeds=None, effective=False):
try:
if seeds is not None or is_netfree:
m = ecell4_base.core.NetfreeModel()
else:
m = ecell4_base.core.NetworkModel()
for sp in SPECIES_ATTRIBUTES:
m.add_species_attribute(sp)
for rr in REACTION_RULES:
m.add_reaction_rule(rr)
if not without_reset:
reset_model()
if seeds is not None:
return m.expand(seeds)
if isinstance(m, ecell4_base.core.NetfreeModel):
m.set_effective(effective)
except Exception as e:
reset_model()
raise e
return m |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_multiprocessing'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'jobs'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'nproc'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'block', 'children': ['15', '74', '217', '253']}, {'id': '15', 'type': 'function_definition', 'children': ['16', '17', '21']}; {'id': '16', 'type': 'function_name', 'children': [], 'value': 'consumer'}, {'id': '17', 'type': 'parameters', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'q_in'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'q_out'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'while_statement', 'children': ['23', '24']}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '33', '45', '51', '61', '67']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'q_in'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '44']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'q_in'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'task_done'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'break_statement', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}, {'id': '47', 'type': 'pattern_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '54', 'type': 'tuple', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'list_splat', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'}, {'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': 'q_in'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'task_done'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'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': 'q_out'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '74', 'type': 'function_definition', 'children': ['75', '76', '80']}, {'id': '75', 'type': 'function_name', 'children': [], 'value': 'mulpmap'}; {'id': '76', 'type': 'parameters', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'nproc'}; {'id': '80', 'type': 'block', 'children': ['81', '91', '99', '107', '134', '154', '161', '175', '185', '191', '206']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'nproc'}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'or'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'nproc'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cpu_count'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'q_in'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'JoinableQueue'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'q_out'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'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': 'workers'}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '128']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'Process'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '119', '125']}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'consumer'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '121', 'type': 'tuple', 'children': ['122', '123', '124']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'q_in'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'q_out'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'daemon'}, {'id': '127', 'type': 'True', 'children': []}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'nproc'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sent'}, {'id': '137', 'type': 'list_comprehension', 'children': ['138', '146']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'q_in'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '146', 'type': 'for_in_clause', 'children': ['147', '150']}, {'id': '147', 'type': 'pattern_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'num_tasks'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'sent'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'list_comprehension', 'children': ['163', '169']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'q_in'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'put'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'None', 'children': []}, {'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'nproc'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'list_comprehension', 'children': ['177', '182']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '181', 'type': 'argument_list', 'children': []}; {'id': '182', 'type': 'for_in_clause', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'workers'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'q_in'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '190', 'type': 'argument_list', 'children': []}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '194', 'type': 'list_comprehension', 'children': ['195', '200']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'q_out'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '199', 'type': 'argument_list', 'children': []}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'num_tasks'}; {'id': '206', 'type': 'return_statement', 'children': ['207']}, {'id': '207', 'type': 'list_comprehension', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '209', 'type': 'for_in_clause', 'children': ['210', '213']}; {'id': '210', 'type': 'tuple_pattern', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'mulpmap'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224', '252']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '224', 'type': 'generator_expression', 'children': ['225', '233']}, {'id': '225', 'type': 'tuple', 'children': ['226', '227', '230']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'job'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'for_in_clause', 'children': ['234', '239']}; {'id': '234', 'type': 'pattern_list', 'children': ['235', '238']}, {'id': '235', 'type': 'tuple_pattern', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'product'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '248']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'jobs'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'nproc'}, {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'list_comprehension', 'children': ['255', '263']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '257', 'type': 'slice', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '259', 'type': 'colon', 'children': []}; {'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '263', 'type': 'for_in_clause', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269', '273']}; {'id': '268', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'n'} | def run_multiprocessing(target, jobs, n=1, nproc=None, **kwargs):
def consumer(f, q_in, q_out):
while True:
val = q_in.get()
if val is None:
q_in.task_done()
break
i, x = val
res = (i, f(*x))
q_in.task_done()
q_out.put(res)
def mulpmap(f, X, nproc):
nproc = nproc or multiprocessing.cpu_count()
q_in = multiprocessing.JoinableQueue()
q_out = multiprocessing.Queue()
workers = [multiprocessing.Process(target=consumer, args=(f, q_in, q_out), daemon=True) for _ in range(nproc)]
sent = [q_in.put((i, x)) for i, x in enumerate(X)]
num_tasks = len(sent)
[q_in.put(None) for _ in range(nproc)]
[w.start() for w in workers]
q_in.join()
res = [q_out.get() for _ in range(num_tasks)]
return [x for (_, x) in sorted(res)]
res = mulpmap(
target, ((job, i + 1, j + 1) for (i, job), j in itertools.product(enumerate(jobs), range(n))), nproc)
return [res[i: i + n] for i in range(0, len(res), n)] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'readbits'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '36', '40', '46', '105', '208']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '26']}, {'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'and'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': '=='}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'bits'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'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': '_bits_pending'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_read_bytes_aligned'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '//'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'bits'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'masks'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_masks'}; {'id': '46', 'type': 'function_definition', 'children': ['47', '48', '53']}, {'id': '47', 'type': 'function_name', 'children': [], 'value': 'transfer_bits'}; {'id': '48', 'type': 'parameters', 'children': ['49', '50', '51', '52']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '53', 'type': 'block', 'children': ['54', '68', '74', '82', '94']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'expression_list', 'children': ['61', '67']}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '66'], 'value': '|'}; {'id': '62', 'type': 'parenthesized_expression', 'children': ['63']}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '<<'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'mask'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'masks'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'remainmask'}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'masks'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '-'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'taken'}, {'id': '85', 'type': 'parenthesized_expression', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '93'], 'value': '&'}, {'id': '87', 'type': 'parenthesized_expression', 'children': ['88']}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '>>'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '-'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'expression_list', 'children': ['96', '102']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '101'], 'value': '|'}, {'id': '97', 'type': 'parenthesized_expression', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '<<'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'taken'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '&'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'remainmask'}, {'id': '105', 'type': 'while_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '>'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'bits'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'block', 'children': ['110', '175', '186', '193', '202']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '>'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'block', 'children': ['117', '123', '133', '151', '164', '170', '174']}, {'id': '117', 'type': 'assert_statement', 'children': ['118']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': 'is'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_partial_byte'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'bits'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '140']}, {'id': '135', 'type': 'pattern_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_partial_byte'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'transfer_bits'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144', '147', '150']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_partial_byte'}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'take'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '157']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': '=='}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_partial_byte'}, {'id': '163', 'type': 'None', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'augmented_assignment', 'children': ['166', '169'], 'value': '-='}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'augmented_assignment', 'children': ['172', '173'], 'value': '-='}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'bits'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '174', 'type': 'continue_statement', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '178', 'type': 'call', 'children': ['179', '184']}, {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '=='}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '189', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'raise_statement', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'EOFError'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '_partial_byte'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': '_bits_pending'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '208', 'type': 'return_statement', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'out'} | def readbits(self, bits):
if bits == 0:
return 0
if bits % 8 == 0 and self._bits_pending == 0:
return self._read_bytes_aligned(bits // 8)
out = 0
masks = self._masks
def transfer_bits(x, y, n, t):
if n == t:
return (x << t) | y, 0
mask = masks[t]
remainmask = masks[n - t]
taken = ((y >> n - t) & mask)
return (x << t) | taken, y & remainmask
while bits > 0:
if self._bits_pending > 0:
assert self._partial_byte is not None
take = min(self._bits_pending, bits)
out, self._partial_byte = transfer_bits(out, self._partial_byte, self._bits_pending, take)
if take == self._bits_pending:
self._partial_byte = None
self._bits_pending -= take
bits -= take
continue
r = self.f.read(1)
if r == b'':
raise EOFError
self._partial_byte = ord(r)
self._bits_pending = 8
return out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'swf'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'export_opts'}, {'id': '9', 'type': 'block', 'children': ['10', '65', '71', '96', '230', '236', '242']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16', '21']}, {'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': 'shape'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Tag'}; {'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': 'shape_tag'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23', '44']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'shapes'}; {'id': '26', 'type': 'list_comprehension', 'children': ['27', '28', '38']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'swf'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'all_tags_of_type'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'tuple', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'TagDefineShape'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'TagDefineSprite'}; {'id': '38', 'type': 'if_clause', 'children': ['39']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': '=='}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'characterId'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '49', '56']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shapes'}, {'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': 'shape_tag'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'shapes'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'else_clause', 'children': ['57']}, {'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': 'Exception'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"Shape %s not found"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '65', 'type': 'import_from_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'dotted_name', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'swf'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'movie'}, {'id': '69', 'type': 'dotted_name', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'SWF'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'example_place_objects'}; {'id': '74', 'type': 'list_comprehension', 'children': ['75', '76', '84']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'swf'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'all_tags_of_type'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'TagPlaceObject'}; {'id': '84', 'type': 'if_clause', 'children': ['85']}, {'id': '85', 'type': 'boolean_operator', 'children': ['86', '89'], 'value': 'and'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'hasCharacter'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'characterId'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'shape_tag'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'characterId'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '101', '202']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'example_place_objects'}, {'id': '101', 'type': 'block', 'children': ['102', '108', '116', '124', '130', '134', '189', '195']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'place_object'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'example_place_objects'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'characters'}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'swf'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'build_dictionary'}, {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ids_to_export'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'place_object'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_dependencies'}, {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ids_exported'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tags_to_export'}, {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'while_statement', 'children': ['135', '139']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ids_to_export'}, {'id': '139', 'type': 'block', 'children': ['140', '148', '158', '164', '175', '182']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ids_to_export'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'if_statement', 'children': ['149', '156']}, {'id': '149', 'type': 'boolean_operator', 'children': ['150', '153'], 'value': 'or'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'in'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ids_exported'}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'not'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'characters'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'continue_statement', 'children': []}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'characters'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ids_to_export'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_dependencies'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'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': 'tags_to_export'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'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': 'ids_exported'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'id'}, {'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': 'tags_to_export'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '194', 'type': 'argument_list', 'children': []}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tags_to_export'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'place_object'}; {'id': '202', 'type': 'else_clause', 'children': ['203']}, {'id': '203', 'type': 'block', 'children': ['204', '210', '216', '224']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'place_object'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'TagPlaceObject'}, {'id': '209', 'type': 'argument_list', 'children': []}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'place_object'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'hasCharacter'}, {'id': '215', 'type': 'True', 'children': []}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'place_object'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'characterId'}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'shape_tag'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'characterId'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'tags_to_export'}, {'id': '227', 'type': 'list', 'children': ['228', '229'], 'value': '[ shape_tag, place_object ]'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'shape_tag'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'place_object'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'stunt_swf'}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'SWF'}, {'id': '235', 'type': 'argument_list', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'stunt_swf'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'tags_to_export'}; {'id': '242', 'type': 'return_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '251']}; {'id': '244', 'type': 'attribute', 'children': ['245', '250']}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'SingleShapeSVGExporterMixin'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'export'}, {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'stunt_swf'}, {'id': '253', 'type': 'dictionary_splat', 'children': ['254']} | def export(self, swf, shape, **export_opts):
if isinstance(shape, Tag):
shape_tag = shape
else:
shapes = [x for x in swf.all_tags_of_type((TagDefineShape, TagDefineSprite)) if x.characterId == shape]
if len(shapes):
shape_tag = shapes[0]
else:
raise Exception("Shape %s not found" % shape)
from swf.movie import SWF
example_place_objects = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.hasCharacter and x.characterId == shape_tag.characterId]
if len(example_place_objects):
place_object = example_place_objects[0]
characters = swf.build_dictionary()
ids_to_export = place_object.get_dependencies()
ids_exported = set()
tags_to_export = []
while len(ids_to_export):
id = ids_to_export.pop()
if id in ids_exported or id not in characters:
continue
tag = characters[id]
ids_to_export.update(tag.get_dependencies())
tags_to_export.append(tag)
ids_exported.add(id)
tags_to_export.reverse()
tags_to_export.append(place_object)
else:
place_object = TagPlaceObject()
place_object.hasCharacter = True
place_object.characterId = shape_tag.characterId
tags_to_export = [ shape_tag, place_object ]
stunt_swf = SWF()
stunt_swf.tags = tags_to_export
return super(SingleShapeSVGExporterMixin, self).export(stunt_swf, **export_opts) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw_residual'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'yerr'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'xerr'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'show_errbars'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'zero_line'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '30', '43', '119', '152', '162']}, {'id': '23', 'type': 'import_from_statement', 'children': ['24', '26']}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'matplotlib'}; {'id': '26', 'type': 'aliased_import', 'children': ['27', '29']}, {'id': '27', 'type': 'dotted_name', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pyplot'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '33', 'type': 'conditional_expression', 'children': ['34', '39', '42'], 'value': 'if'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'gca'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '45', '82']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'show_errbars'}, {'id': '45', 'type': 'block', 'children': ['46', '58', '65']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'plotopts'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '55']}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'b.'"}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'capsize'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'plotopts'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pp'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'errorbar'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '76', '77', '80']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'yerr'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'xerr'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'zorder'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'dictionary_splat', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'plotopts'}; {'id': '82', 'type': 'else_clause', 'children': ['83']}, {'id': '83', 'type': 'block', 'children': ['84', '93', '100']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'plotopts'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'k'"}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'plotopts'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pp'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'bar'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '111', '112', '117']}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '-'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'xerr'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '*'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'xerr'}, {'id': '117', 'type': 'dictionary_splat', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'plotopts'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'zero_line'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'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': 'ax'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'plot'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '145', '148', '149']}; {'id': '128', 'type': 'list', 'children': ['129', '136'], 'value': '[x[0] - xerr[0], x[-1] + xerr[-1]]'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '-'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'xerr'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '141'], 'value': '+'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'xerr'}, {'id': '143', 'type': 'unary_operator', 'children': ['144'], 'value': '-'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '145', 'type': 'list', 'children': ['146', '147'], 'value': '[0, 0]'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'r-'"}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'zorder'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'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': 'ax'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '162', 'type': 'return_statement', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ax'} | def draw_residual(x, y, yerr, xerr,
show_errbars=True, ax=None,
zero_line=True, grid=True,
**kwargs):
from matplotlib import pyplot as plt
ax = plt.gca() if ax is None else ax
if show_errbars:
plotopts = dict(fmt='b.', capsize=0)
plotopts.update(kwargs)
pp = ax.errorbar(x, y, yerr, xerr, zorder=0, **plotopts)
else:
plotopts = dict(color='k')
plotopts.update(kwargs)
pp = ax.bar(x - xerr, y, width=2*xerr, **plotopts)
if zero_line:
ax.plot([x[0] - xerr[0], x[-1] + xerr[-1]], [0, 0], 'r-', zorder=2)
if grid:
ax.grid(grid)
return ax |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combined_message_class'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '21', '25', '53', '115', '129']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '__combined_message_class'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '__combined_message_class'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'field_number'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '34']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'body_message_class'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'all_fields'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '49']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '42']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_CopyField'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'field_number'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'field_number'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '62']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'field'}, {'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': 'parameters_message_class'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'all_fields'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63', '97', '111']}, {'id': '63', 'type': 'if_statement', 'children': ['64', '69']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': 'in'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '81', '94']}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_CompareFields'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '90'], 'value': '%'}, {'id': '87', 'type': 'concatenated_string', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'Field %r contained in both parameters and request '"}, {'id': '89', 'type': 'string', 'children': [], 'value': "'body, but the fields differ.'"}; {'id': '90', 'type': 'tuple', 'children': ['91']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'continue_statement', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '104']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_CopyField'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'field_number'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'augmented_assignment', 'children': ['113', '114'], 'value': '+='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'field_number'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '__combined_message_class'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '128']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'CombinedContainer'"}; {'id': '124', 'type': 'tuple', 'children': ['125']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'Message'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'} | def combined_message_class(self):
if self.__combined_message_class is not None:
return self.__combined_message_class
fields = {}
field_number = 1
for field in self.body_message_class.all_fields():
fields[field.name] = _CopyField(field, number=field_number)
field_number += 1
for field in self.parameters_message_class.all_fields():
if field.name in fields:
if not _CompareFields(field, fields[field.name]):
raise TypeError('Field %r contained in both parameters and request '
'body, but the fields differ.' % (field.name,))
else:
continue
fields[field.name] = _CopyField(field, number=field_number)
field_number += 1
self.__combined_message_class = type('CombinedContainer',
(messages.Message,), fields)
return self.__combined_message_class |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_token'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '12']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'allowed_auth_schemes'}, {'id': '9', 'type': 'tuple', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'OAuth'"}, {'id': '11', 'type': 'string', 'children': [], 'value': "'Bearer'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'allowed_query_keys'}; {'id': '14', 'type': 'tuple', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'bearer_token'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'access_token'"}, {'id': '17', 'type': 'block', 'children': ['18', '29', '40', '68']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'allowed_auth_schemes'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_listlike_guard'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'allowed_auth_schemes'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'allowed_auth_schemes'"}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'iterable_only'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'auth_header'}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'HTTP_AUTHORIZATION'"}; {'id': '40', 'type': 'if_statement', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'auth_header'}; {'id': '42', 'type': 'block', 'children': ['43', '66']}, {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'auth_scheme'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'allowed_auth_schemes'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '54']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'auth_header'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'auth_scheme'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'auth_header'}; {'id': '58', 'type': 'slice', 'children': ['59', '65']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '64'], 'value': '+'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'auth_scheme'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'colon', 'children': []}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '70', 'type': 'block', 'children': ['71', '82']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'allowed_query_keys'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_listlike_guard'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'allowed_query_keys'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'allowed_query_keys'"}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'iterable_only'}, {'id': '81', 'type': 'True', 'children': []}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'allowed_query_keys'}, {'id': '85', 'type': 'block', 'children': ['86', '97']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'pattern_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get_unrecognized_field_info'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'token'} | def _get_token(
request=None, allowed_auth_schemes=('OAuth', 'Bearer'),
allowed_query_keys=('bearer_token', 'access_token')):
allowed_auth_schemes = _listlike_guard(
allowed_auth_schemes, 'allowed_auth_schemes', iterable_only=True)
auth_header = os.environ.get('HTTP_AUTHORIZATION')
if auth_header:
for auth_scheme in allowed_auth_schemes:
if auth_header.startswith(auth_scheme):
return auth_header[len(auth_scheme) + 1:]
return None
if request:
allowed_query_keys = _listlike_guard(
allowed_query_keys, 'allowed_query_keys', iterable_only=True)
for key in allowed_query_keys:
token, _ = request.get_unrecognized_field_info(key)
if token:
return token |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_id_token_user'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'for_statement', 'children': ['12', '15', '20']}; {'id': '12', 'type': 'pattern_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'issuer_key'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'issuer'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '30', '59', '72', '85']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'issuer_cert_uri'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'convert_jwks_uri'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'issuer'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'jwks_uri'}; {'id': '30', 'type': 'try_statement', 'children': ['31', '44']}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_verify_signed_jwt_with_certs'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40', '41']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'time_now'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cert_uri'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'issuer_cert_uri'}; {'id': '44', 'type': 'except_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '46', 'type': 'block', 'children': ['47', '58']}, {'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': '_logger'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'id_token verification failed for issuer %s'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'issuer_key'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'exc_info'}, {'id': '57', 'type': 'True', 'children': []}; {'id': '58', 'type': 'continue_statement', 'children': []}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'issuer_values'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_listlike_guard'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '68', '69']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'issuer'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'issuer'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'issuer'"}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'log_warning'}, {'id': '71', 'type': 'False', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_Mapping'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'issuer_key'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '101']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_verify_parsed_token'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91', '92', '93']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'issuer_values'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'is_legacy_google_auth'}, {'id': '95', 'type': 'parenthesized_expression', 'children': ['96']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '=='}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'issuer'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'issuer'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_ISSUERS'}, {'id': '101', 'type': 'block', 'children': ['102', '108']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'email'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'users'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'User'}, {'id': '113', 'type': 'argument_list', 'children': ['114']} | def _get_id_token_user(token, issuers, audiences, allowed_client_ids, time_now, cache):
for issuer_key, issuer in issuers.items():
issuer_cert_uri = convert_jwks_uri(issuer.jwks_uri)
try:
parsed_token = _verify_signed_jwt_with_certs(
token, time_now, cache, cert_uri=issuer_cert_uri)
except Exception:
_logger.debug(
'id_token verification failed for issuer %s', issuer_key, exc_info=True)
continue
issuer_values = _listlike_guard(issuer.issuer, 'issuer', log_warning=False)
if isinstance(audiences, _Mapping):
audiences = audiences[issuer_key]
if _verify_parsed_token(
parsed_token, issuer_values, audiences, allowed_client_ids,
is_legacy_google_auth=(issuer.issuer == _ISSUERS)):
email = parsed_token['email']
return users.User(email) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_verify_parsed_token'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'is_legacy_google_auth'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '37', '46', '59', '68', '82', '96', '136', '143']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '21']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '20'], 'value': 'not'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'iss'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'issuers'}, {'id': '21', 'type': 'block', 'children': ['22', '35']}; {'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': '_logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Issuer was not valid: %s'"}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'iss'"}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'False', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'aud'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'aud'"}; {'id': '46', 'type': 'if_statement', 'children': ['47', '49']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'aud'}, {'id': '49', 'type': 'block', 'children': ['50', '57']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'No aud field in token'"}, {'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': 'cid'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'azp'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'audience_allowed'}, {'id': '71', 'type': 'boolean_operator', 'children': ['72', '76'], 'value': 'or'}; {'id': '72', 'type': 'parenthesized_expression', 'children': ['73']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'aud'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '76', 'type': 'parenthesized_expression', 'children': ['77']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '79'], 'value': 'and'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'is_legacy_google_auth'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '=='}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'aud'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '85']}, {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'audience_allowed'}, {'id': '85', 'type': 'block', 'children': ['86', '94']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'Audience not allowed: %s'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'aud'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'False', 'children': []}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'is_legacy_google_auth'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '106', '118']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '105'], 'value': '=='}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'SKIP_CLIENT_ID_CHECK'}; {'id': '106', 'type': 'block', 'children': ['107', '116']}, {'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': '_logger'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'concatenated_string', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'Client ID check can\\'t be skipped for ID tokens. '"}, {'id': '115', 'type': 'string', 'children': [], 'value': "'Id_token cannot be verified.'"}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'False', 'children': []}; {'id': '118', 'type': 'elif_clause', 'children': ['119', '125']}, {'id': '119', 'type': 'boolean_operator', 'children': ['120', '122'], 'value': 'or'}; {'id': '120', 'type': 'not_operator', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '125', 'type': 'block', 'children': ['126', '134']}; {'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': 'warning'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'Client ID is not allowed: %s'"}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '134', 'type': 'return_statement', 'children': ['135']}, {'id': '135', 'type': 'False', 'children': []}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'not'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'email'"}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parsed_token'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'False', 'children': []}, {'id': '143', 'type': 'return_statement', 'children': ['144']} | def _verify_parsed_token(parsed_token, issuers, audiences, allowed_client_ids, is_legacy_google_auth=True):
if parsed_token.get('iss') not in issuers:
_logger.warning('Issuer was not valid: %s', parsed_token.get('iss'))
return False
aud = parsed_token.get('aud')
if not aud:
_logger.warning('No aud field in token')
return False
cid = parsed_token.get('azp')
audience_allowed = (aud in audiences) or (is_legacy_google_auth and aud == cid)
if not audience_allowed:
_logger.warning('Audience not allowed: %s', aud)
return False
if is_legacy_google_auth:
if list(allowed_client_ids) == SKIP_CLIENT_ID_CHECK:
_logger.warning('Client ID check can\'t be skipped for ID tokens. '
'Id_token cannot be verified.')
return False
elif not cid or cid not in allowed_client_ids:
_logger.warning('Client ID is not allowed: %s', cid)
return False
if 'email' not in parsed_token:
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_verify_signed_jwt_with_certs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'jwt'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'time_now'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cert_uri'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': '_DEFAULT_CERT_URI'}; {'id': '10', 'type': 'block', 'children': ['11', '20', '35', '47', '56', '69', '78', '96', '118', '126', '136', '148', '161', '165', '252', '261', '270', '288', '297', '307', '313', '322', '332', '344', '350', '364', '378']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'jwt'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '20', 'type': 'if_statement', 'children': ['21', '27']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '26'], 'value': '!='}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '3'}, {'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': '_AppIdentityError'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'concatenated_string', 'children': ['33', '34']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'Token is not an id_token (Wrong number of '"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'segments)'"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'%s.%s'"}; {'id': '40', 'type': 'tuple', 'children': ['41', '44']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_urlsafe_b64decode'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lsignature'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'long'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '68']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'signature'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'hex'"}; {'id': '68', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'header_body'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_urlsafe_b64decode'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'try_statement', 'children': ['79', '89']}, {'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': 'header'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'header_body'}, {'id': '89', 'type': 'except_clause', 'children': ['90']}; {'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': '_AppIdentityError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Can\'t parse header"'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '105']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '104'], 'value': '!='}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'alg'"}; {'id': '104', 'type': 'string', 'children': [], 'value': "'RS256'"}, {'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': '_AppIdentityError'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '%'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'Unexpected encryption algorithm: %r'"}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'alg'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'certs'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': '_get_cached_certs'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'cert_uri'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'certs'}, {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'raise_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': "'Unable to retrieve certs needed to verify the signed JWT'"}; {'id': '136', 'type': 'if_statement', 'children': ['137', '139']}, {'id': '137', 'type': 'not_operator', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_CRYPTO_LOADED'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'raise_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'concatenated_string', 'children': ['145', '146', '147']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'Unable to load pycrypto library. Can\\'t verify '"}; {'id': '146', 'type': 'string', 'children': [], 'value': "'id_token signature. See http://www.pycrypto.org '"}, {'id': '147', 'type': 'string', 'children': [], 'value': "'for more information on pycrypto.'"}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'local_hash'}, {'id': '151', 'type': 'call', 'children': ['152', '160']}; {'id': '152', 'type': 'attribute', 'children': ['153', '159']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'SHA256'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'new'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'signed'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'hexdigest'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'verified'}; {'id': '164', 'type': 'False', 'children': []}, {'id': '165', 'type': 'for_statement', 'children': ['166', '167', '170']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'keyvalue'}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'certs'}, {'id': '169', 'type': 'string', 'children': [], 'value': "'keyvalues'"}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'try_statement', 'children': ['172', '239']}; {'id': '172', 'type': 'block', 'children': ['173', '182', '191', '202', '216', '225', '235']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'modulus'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': '_b64_to_long'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'keyvalue'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'modulus'"}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'exponent'}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '_b64_to_long'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'keyvalue'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'exponent'"}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'RSA'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'construct'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'tuple', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'modulus'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'exponent'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'hexsig'}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '%'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'%064x'"}, {'id': '207', 'type': 'subscript', 'children': ['208', '215']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'encrypt'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'lsignature'}; {'id': '214', 'type': 'string', 'children': [], 'value': "''"}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'hexsig'}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'hexsig'}, {'id': '221', 'type': 'slice', 'children': ['222', '224']}; {'id': '222', 'type': 'unary_operator', 'children': ['223'], 'value': '-'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '64'}; {'id': '224', 'type': 'colon', 'children': []}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'verified'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'hmac'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'compare_digest'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'hexsig'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'local_hash'}, {'id': '235', 'type': 'if_statement', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'verified'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'break_statement', 'children': []}, {'id': '239', 'type': 'except_clause', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '242', 'type': 'block', 'children': ['243', '251']}, {'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': '_logger'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '250']}, {'id': '249', 'type': 'string', 'children': [], 'value': "'Signature verification error: %s; continuing with the next cert.'"}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '251', 'type': 'continue_statement', 'children': []}; {'id': '252', 'type': 'if_statement', 'children': ['253', '255']}, {'id': '253', 'type': 'not_operator', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'verified'}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'raise_statement', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'Invalid token signature'"}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'json_body'}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': '_urlsafe_b64decode'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '270', 'type': 'try_statement', 'children': ['271', '281']}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'json_body'}, {'id': '281', 'type': 'except_clause', 'children': ['282']}; {'id': '282', 'type': 'block', 'children': ['283']}, {'id': '283', 'type': 'raise_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'string', 'children': [], 'value': '"Can\'t parse token body"'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'iat'}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'string', 'children': [], 'value': "'iat'"}, {'id': '297', 'type': 'if_statement', 'children': ['298', '301']}; {'id': '298', 'type': 'comparison_operator', 'children': ['299', '300'], 'value': 'is'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'iat'}; {'id': '300', 'type': 'None', 'children': []}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'raise_statement', 'children': ['303']}, {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'No iat field in token'"}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'earliest'}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '-'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'iat'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': '_CLOCK_SKEW_SECS'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'string', 'children': [], 'value': "'exp'"}; {'id': '322', 'type': 'if_statement', 'children': ['323', '326']}, {'id': '323', 'type': 'comparison_operator', 'children': ['324', '325'], 'value': 'is'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '325', 'type': 'None', 'children': []}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'raise_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'string', 'children': [], 'value': "'No exp field in token'"}; {'id': '332', 'type': 'if_statement', 'children': ['333', '338']}, {'id': '333', 'type': 'comparison_operator', 'children': ['334', '335'], 'value': '>='}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '335', 'type': 'binary_operator', 'children': ['336', '337'], 'value': '+'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': '_MAX_TOKEN_LIFETIME_SECS'}; {'id': '338', 'type': 'block', 'children': ['339']}, {'id': '339', 'type': 'raise_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}, {'id': '343', 'type': 'string', 'children': [], 'value': "'exp field too far in future'"}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}, {'id': '345', 'type': 'assignment', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'latest'}, {'id': '347', 'type': 'binary_operator', 'children': ['348', '349'], 'value': '+'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': '_CLOCK_SKEW_SECS'}; {'id': '350', 'type': 'if_statement', 'children': ['351', '354']}, {'id': '351', 'type': 'comparison_operator', 'children': ['352', '353'], 'value': '<'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'earliest'}; {'id': '354', 'type': 'block', 'children': ['355']}, {'id': '355', 'type': 'raise_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'binary_operator', 'children': ['360', '361'], 'value': '%'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'Token used too early, %d < %d'"}, {'id': '361', 'type': 'tuple', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'earliest'}; {'id': '364', 'type': 'if_statement', 'children': ['365', '368']}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '367'], 'value': '>'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'latest'}; {'id': '368', 'type': 'block', 'children': ['369']}, {'id': '369', 'type': 'raise_statement', 'children': ['370']}; {'id': '370', 'type': 'call', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': '_AppIdentityError'}; {'id': '372', 'type': 'argument_list', 'children': ['373']}, {'id': '373', 'type': 'binary_operator', 'children': ['374', '375'], 'value': '%'}; {'id': '374', 'type': 'string', 'children': [], 'value': "'Token used too late, %d > %d'"}, {'id': '375', 'type': 'tuple', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'time_now'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'latest'}; {'id': '378', 'type': 'return_statement', 'children': ['379']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'parsed'} | def _verify_signed_jwt_with_certs(
jwt, time_now, cache,
cert_uri=_DEFAULT_CERT_URI):
segments = jwt.split('.')
if len(segments) != 3:
raise _AppIdentityError('Token is not an id_token (Wrong number of '
'segments)')
signed = '%s.%s' % (segments[0], segments[1])
signature = _urlsafe_b64decode(segments[2])
lsignature = long(signature.encode('hex'), 16)
header_body = _urlsafe_b64decode(segments[0])
try:
header = json.loads(header_body)
except:
raise _AppIdentityError("Can't parse header")
if header.get('alg') != 'RS256':
raise _AppIdentityError('Unexpected encryption algorithm: %r' %
header.get('alg'))
certs = _get_cached_certs(cert_uri, cache)
if certs is None:
raise _AppIdentityError(
'Unable to retrieve certs needed to verify the signed JWT')
if not _CRYPTO_LOADED:
raise _AppIdentityError('Unable to load pycrypto library. Can\'t verify '
'id_token signature. See http://www.pycrypto.org '
'for more information on pycrypto.')
local_hash = SHA256.new(signed).hexdigest()
verified = False
for keyvalue in certs['keyvalues']:
try:
modulus = _b64_to_long(keyvalue['modulus'])
exponent = _b64_to_long(keyvalue['exponent'])
key = RSA.construct((modulus, exponent))
hexsig = '%064x' % key.encrypt(lsignature, '')[0]
hexsig = hexsig[-64:]
verified = hmac.compare_digest(hexsig, local_hash)
if verified:
break
except Exception, e:
_logger.debug(
'Signature verification error: %s; continuing with the next cert.', e)
continue
if not verified:
raise _AppIdentityError('Invalid token signature')
json_body = _urlsafe_b64decode(segments[1])
try:
parsed = json.loads(json_body)
except:
raise _AppIdentityError("Can't parse token body")
iat = parsed.get('iat')
if iat is None:
raise _AppIdentityError('No iat field in token')
earliest = iat - _CLOCK_SKEW_SECS
exp = parsed.get('exp')
if exp is None:
raise _AppIdentityError('No exp field in token')
if exp >= time_now + _MAX_TOKEN_LIFETIME_SECS:
raise _AppIdentityError('exp field too far in future')
latest = exp + _CLOCK_SKEW_SECS
if time_now < earliest:
raise _AppIdentityError('Token used too early, %d < %d' %
(time_now, earliest))
if time_now > latest:
raise _AppIdentityError('Token used too late, %d > %d' %
(time_now, latest))
return parsed |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_methods'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'methods'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '166']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'methods'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'methods'}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '18']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': '_sorted_methods_comparison'}, {'id': '15', 'type': 'parameters', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'method_info1'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'method_info2'}; {'id': '18', 'type': 'block', 'children': ['19', '70', '85', '100', '109', '133', '140', '164']}, {'id': '19', 'type': 'function_definition', 'children': ['20', '21', '23']}; {'id': '20', 'type': 'function_name', 'children': [], 'value': '_score_path'}, {'id': '21', 'type': 'parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '23', 'type': 'block', 'children': ['24', '28', '37', '59', '68']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '40', 'type': 'block', 'children': ['41', '45']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '<<='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '54']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '49'], 'value': 'or'}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '!='}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'{'"}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'augmented_assignment', 'children': ['61', '62'], 'value': '<<='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '-'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '31'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'path_score1'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_score_path'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '82']}, {'id': '77', 'type': 'attribute', 'children': ['78', '81']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'method_info1'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "''"}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'path_score2'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_score_path'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'method_info2'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '99', 'type': 'string', 'children': [], 'value': "''"}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '!='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'path_score1'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'path_score2'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '-'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'path_score2'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'path_score1'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'path_result'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '124']}, {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'method_info1'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '123', 'type': 'string', 'children': [], 'value': "''"}; {'id': '124', 'type': 'call', 'children': ['125', '130']}, {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'method_info2'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '132', 'type': 'string', 'children': [], 'value': "''"}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '!='}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'path_result'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'return_statement', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'path_result'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'method_result'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'cmp'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '155']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'method_info1'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': "'httpMethod'"}; {'id': '154', 'type': 'string', 'children': [], 'value': "''"}, {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'method_info2'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'httpMethod'"}, {'id': '163', 'type': 'string', 'children': [], 'value': "''"}; {'id': '164', 'type': 'return_statement', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'method_result'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '175']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'methods'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_sorted_methods_comparison'} | def _get_sorted_methods(self, methods):
if not methods:
return methods
def _sorted_methods_comparison(method_info1, method_info2):
def _score_path(path):
score = 0
parts = path.split('/')
for part in parts:
score <<= 1
if not part or part[0] != '{':
score += 1
score <<= 31 - len(parts)
return score
path_score1 = _score_path(method_info1[1].get('path', ''))
path_score2 = _score_path(method_info2[1].get('path', ''))
if path_score1 != path_score2:
return path_score2 - path_score1
path_result = cmp(method_info1[1].get('path', ''),
method_info2[1].get('path', ''))
if path_result != 0:
return path_result
method_result = cmp(method_info1[1].get('httpMethod', ''),
method_info2[1].get('httpMethod', ''))
return method_result
return sorted(methods.items(), _sorted_methods_comparison) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'api_server'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'api_services'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '25', '32', '40', '49', '58', '69', '86', '102', '109', '116', '124', '137', '143', '149']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'protocols'"}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': 'TypeError'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"__init__() got an unexpected keyword argument \'protocols\'"'}; {'id': '18', 'type': 'import_from_statement', 'children': ['19', '21']}, {'id': '19', 'type': 'relative_import', 'children': ['20']}; {'id': '20', 'type': 'import_prefix', 'children': []}, {'id': '21', 'type': 'aliased_import', 'children': ['22', '24']}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'endpoints_logger'}, {'id': '25', 'type': 'import_from_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'relative_import', 'children': ['27']}, {'id': '27', 'type': 'import_prefix', 'children': []}; {'id': '28', 'type': 'aliased_import', 'children': ['29', '31']}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__version__'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'endpoints_version'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'endpoints_logger'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'Initializing Endpoints Framework version %s'"}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'endpoints_version'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'apis_app'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_ApiServer'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'api_services'}, {'id': '47', 'type': 'dictionary_splat', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'endpoints_dispatcher'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'EndpointsDispatcherMiddleware'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'apis_app'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'service_name'}, {'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': 'environ'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'ENDPOINTS_SERVICE_NAME'"}, {'id': '69', 'type': 'if_statement', 'children': ['70', '72']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'service_name'}; {'id': '72', 'type': 'block', 'children': ['73', '84']}, {'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': '_logger'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'concatenated_string', 'children': ['80', '81', '82', '83']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'Did not specify the ENDPOINTS_SERVICE_NAME environment'"}, {'id': '81', 'type': 'string', 'children': [], 'value': "' variable so service control is disabled. Please specify'"}; {'id': '82', 'type': 'string', 'children': [], 'value': "' the name of service in ENDPOINTS_SERVICE_NAME to enable'"}, {'id': '83', 'type': 'string', 'children': [], 'value': "' it.'"}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '92']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'control_wsgi'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'running_on_devserver'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93', '100']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'Running on local devserver, so service control is disabled.'"}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '102', 'type': 'import_from_statement', 'children': ['103', '105']}, {'id': '103', 'type': 'dotted_name', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'endpoints_management'}, {'id': '105', 'type': 'aliased_import', 'children': ['106', '108']}; {'id': '106', 'type': 'dotted_name', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'management_logger'}, {'id': '109', 'type': 'import_from_statement', 'children': ['110', '112']}; {'id': '110', 'type': 'dotted_name', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'endpoints_management'}; {'id': '112', 'type': 'aliased_import', 'children': ['113', '115']}, {'id': '113', 'type': 'dotted_name', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '__version__'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'management_version'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'management_logger'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'Initializing Endpoints Management Framework version %s'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'management_version'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '127', 'type': 'call', 'children': ['128', '135']}; {'id': '128', 'type': 'attribute', 'children': ['129', '134']}, {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'control_client'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'Loaders'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'service_name'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'control_client'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'use_gae_thread'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'return_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'control_wsgi'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'add_all'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '161']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'app_identity'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'get_application_id'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'controller'} | def api_server(api_services, **kwargs):
if 'protocols' in kwargs:
raise TypeError("__init__() got an unexpected keyword argument 'protocols'")
from . import _logger as endpoints_logger
from . import __version__ as endpoints_version
endpoints_logger.info('Initializing Endpoints Framework version %s', endpoints_version)
apis_app = _ApiServer(api_services, **kwargs)
dispatcher = endpoints_dispatcher.EndpointsDispatcherMiddleware(apis_app)
service_name = os.environ.get('ENDPOINTS_SERVICE_NAME')
if not service_name:
_logger.warn('Did not specify the ENDPOINTS_SERVICE_NAME environment'
' variable so service control is disabled. Please specify'
' the name of service in ENDPOINTS_SERVICE_NAME to enable'
' it.')
return dispatcher
if control_wsgi.running_on_devserver():
_logger.warn('Running on local devserver, so service control is disabled.')
return dispatcher
from endpoints_management import _logger as management_logger
from endpoints_management import __version__ as management_version
management_logger.info('Initializing Endpoints Management Framework version %s', management_version)
controller = control_client.Loaders.DEFAULT.load(service_name)
control_client.use_gae_thread()
controller.start()
return control_wsgi.add_all(
dispatcher,
app_identity.get_application_id(),
controller) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__register_services'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'api_name_version_map'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'api_config_registry'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '19', '116']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'generator'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'api_config'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ApiConfigGenerator'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'protorpc_services'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '26']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'service_factories'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'api_name_version_map'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '37', '46', '53']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'service_classes'}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'service_factory'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'service_class'}; {'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'service_factory'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'service_factories'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'config_dict'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'generator'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_config_dict'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'service_classes'}; {'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': 'api_config_registry'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'register_backend'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config_dict'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'service_factory'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'service_factories'}; {'id': '56', 'type': 'block', 'children': ['57', '65', '79', '107']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'protorpc_class_name'}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'service_factory'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'service_class'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'%s%s'"}; {'id': '70', 'type': 'tuple', 'children': ['71', '78']}, {'id': '71', 'type': 'attribute', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'service_factory'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'service_class'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'api_info'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'base_path'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'protorpc_class_name'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '97']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '82', 'type': 'generator_expression', 'children': ['83', '94']}, {'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'or'}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'service_map'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'service_map'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'service_factory'}; {'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'service_map'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'protorpc_services'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'raise_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'api_config'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'ApiConfigurationError'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'Can\\'t reuse the same class in multiple APIs: %s'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'protorpc_class_name'}, {'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': 'protorpc_services'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'tuple', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'service_factory'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'protorpc_services'} | def __register_services(api_name_version_map, api_config_registry):
generator = api_config.ApiConfigGenerator()
protorpc_services = []
for service_factories in api_name_version_map.itervalues():
service_classes = [service_factory.service_class
for service_factory in service_factories]
config_dict = generator.get_config_dict(service_classes)
api_config_registry.register_backend(config_dict)
for service_factory in service_factories:
protorpc_class_name = service_factory.service_class.__name__
root = '%s%s' % (service_factory.service_class.api_info.base_path,
protorpc_class_name)
if any(service_map[0] == root or service_map[1] == service_factory
for service_map in protorpc_services):
raise api_config.ApiConfigurationError(
'Can\'t reuse the same class in multiple APIs: %s' %
protorpc_class_name)
protorpc_services.append((root, service_factory))
return protorpc_services |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'transform_rest_request'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'orig_request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'method_parameters'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '21', '38', '78', '155', '170', '176', '189']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'orig_request'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'for_statement', 'children': ['22', '25', '30']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'list', 'children': ['37'], 'value': '[value]'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'for_statement', 'children': ['44', '47', '54']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'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': 'request'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59', '70']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '+'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72']}; {'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': 'body_json'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '78', 'type': 'for_statement', 'children': ['79', '82', '87']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88', '98', '108', '122', '137', '146']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'current_parameter'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'method_parameters'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'dictionary', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'repeated'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'current_parameter'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'repeated'"}, {'id': '107', 'type': 'False', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '111']}, {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'repeated'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'parameter_converter'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'transform_parameter_value'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133', '136']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'current_parameter'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'message_value'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_add_message_field'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153', '154']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'message_value'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_update_from_body'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'body_json'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'body_json'}, {'id': '189', 'type': 'return_statement', 'children': ['190']} | def transform_rest_request(self, orig_request, params, method_parameters):
request = orig_request.copy()
body_json = {}
for key, value in params.iteritems():
body_json[key] = [value]
if request.parameters:
for key, value in request.parameters.iteritems():
if key in body_json:
body_json[key] = value + body_json[key]
else:
body_json[key] = value
for key, value in body_json.items():
current_parameter = method_parameters.get(key, {})
repeated = current_parameter.get('repeated', False)
if not repeated:
body_json[key] = body_json[key][0]
body_json[key] = parameter_converter.transform_parameter_value(
key, body_json[key], current_parameter)
message_value = body_json.pop(key)
self._add_message_field(key, message_value, body_json)
if request.body_json:
self._update_from_body(body_json, request.body_json)
request.body_json = body_json
request.body = json.dumps(request.body_json)
return request |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '66']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'api'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '51', '54', '57', '60', '63']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hostname'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'canonical_name'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'owner_name'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'package_path'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'frontend_limits'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'documentation'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'default_parameter', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'auth_level'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'default_parameter', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'default_parameter', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'namespace'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'default_parameter', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'default_parameter', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'base_path'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'default_parameter', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'default_parameter', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'use_request_uri'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '79']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '70', 'type': 'None', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_AUTH_LEVEL_WARNING'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_ApiDecorator'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85', '88', '91', '94', '97', '100', '103', '106', '109', '112', '115', '118', '121', '124', '127', '130', '133', '136', '139', '142']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'hostname'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'canonical_name'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'canonical_name'}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}, {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'owner_name'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'owner_name'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'package_path'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'package_path'}, {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'frontend_limits'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'frontend_limits'}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'documentation'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'documentation'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'auth_level'}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'issuers'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'namespace'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'base_path'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'base_path'}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'use_request_uri'} | def api(name, version, description=None, hostname=None, audiences=None,
scopes=None, allowed_client_ids=None, canonical_name=None,
auth=None, owner_domain=None, owner_name=None, package_path=None,
frontend_limits=None, title=None, documentation=None, auth_level=None,
issuers=None, namespace=None, api_key_required=None, base_path=None,
limit_definitions=None, use_request_uri=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
return _ApiDecorator(name, version, description=description,
hostname=hostname, audiences=audiences, scopes=scopes,
allowed_client_ids=allowed_client_ids,
canonical_name=canonical_name, auth=auth,
owner_domain=owner_domain, owner_name=owner_name,
package_path=package_path,
frontend_limits=frontend_limits, title=title,
documentation=documentation, auth_level=auth_level,
issuers=issuers, namespace=namespace,
api_key_required=api_key_required, base_path=base_path,
limit_definitions=limit_definitions,
use_request_uri=use_request_uri) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '44']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'method'}, {'id': '3', 'type': 'parameters', 'children': ['4', '9', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request_message'}; {'id': '6', 'type': 'attribute', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'message_types'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'VoidMessage'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'response_message'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'message_types'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'VoidMessage'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'http_method'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'metric_costs'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'use_request_uri'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '57', '61', '255', '268', '277', '284', '289', '296']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_AUTH_LEVEL_WARNING'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_HTTP_METHOD'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '61', 'type': 'function_definition', 'children': ['62', '63', '65']}; {'id': '62', 'type': 'function_name', 'children': [], 'value': 'apiserving_method_decorator'}, {'id': '63', 'type': 'parameters', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'api_method'}, {'id': '65', 'type': 'block', 'children': ['66', '70', '74', '123', '130', '160', '168', '189', '243', '253']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'request_body_class'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'request_params_class'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '82', '111']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'resource_container'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ResourceContainer'}; {'id': '82', 'type': 'block', 'children': ['83', '95', '103']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'remote_decorator'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'combined_message_class'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'response_message'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'request_body_class'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'body_message_class'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'request_params_class'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'parameters_message_class'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'remote_decorator'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'request_message'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'response_message'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'remote_method'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'remote_decorator'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'api_method'}; {'id': '130', 'type': 'function_definition', 'children': ['131', '132', '135']}, {'id': '131', 'type': 'function_name', 'children': [], 'value': 'invoke_remote'}; {'id': '132', 'type': 'parameters', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'service_instance'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '135', 'type': 'block', 'children': ['136', '154']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'users_id_token'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_maybe_set_current_user_vars'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143', '151']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'api_info'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'service_instance'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'api_info'"}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'remote_method'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'service_instance'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'request'}; {'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': 'invoke_remote'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'remote_method'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '168', 'type': 'if_statement', 'children': ['169', '176']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'resource_container'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ResourceContainer'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '184']}, {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'resource_container'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ResourceContainer'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'request_message'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': '_MethodInfo'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '204', '211', '216', '219', '222', '225', '228', '231', '234', '237', '240']}, {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '199', 'type': 'boolean_operator', 'children': ['200', '201'], 'value': 'or'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'api_method'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '208'], 'value': 'or'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'api_method'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'http_method'}, {'id': '213', 'type': 'boolean_operator', 'children': ['214', '215'], 'value': 'or'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'http_method'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_HTTP_METHOD'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'auth_level'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}, {'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'metric_costs'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'metric_costs'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'use_request_uri'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'use_request_uri'}, {'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'request_body_class'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'request_body_class'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'request_params_class'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'request_params_class'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'invoke_remote'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'endpoints_util'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'check_list_type'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262', '267']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '262', 'type': 'tuple', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'endpoints_types'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'OAuth2Scope'}, {'id': '267', 'type': 'string', 'children': [], 'value': "'scopes'"}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'endpoints_util'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'check_list_type'}, {'id': '273', 'type': 'argument_list', 'children': ['274', '275', '276']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'allowed_client_ids'"}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': '_CheckEnum'}; {'id': '280', 'type': 'argument_list', 'children': ['281', '282', '283']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'AUTH_LEVEL'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'auth_level'"}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': '_CheckAudiences'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': '_CheckType'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '294', '295']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'metric_costs'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '295', 'type': 'string', 'children': [], 'value': "'metric_costs'"}; {'id': '296', 'type': 'return_statement', 'children': ['297']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'apiserving_method_decorator'} | def method(request_message=message_types.VoidMessage,
response_message=message_types.VoidMessage,
name=None,
path=None,
http_method='POST',
scopes=None,
audiences=None,
allowed_client_ids=None,
auth_level=None,
api_key_required=None,
metric_costs=None,
use_request_uri=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
DEFAULT_HTTP_METHOD = 'POST'
def apiserving_method_decorator(api_method):
request_body_class = None
request_params_class = None
if isinstance(request_message, resource_container.ResourceContainer):
remote_decorator = remote.method(request_message.combined_message_class,
response_message)
request_body_class = request_message.body_message_class()
request_params_class = request_message.parameters_message_class()
else:
remote_decorator = remote.method(request_message, response_message)
remote_method = remote_decorator(api_method)
def invoke_remote(service_instance, request):
users_id_token._maybe_set_current_user_vars(
invoke_remote, api_info=getattr(service_instance, 'api_info', None),
request=request)
return remote_method(service_instance, request)
invoke_remote.remote = remote_method.remote
if isinstance(request_message, resource_container.ResourceContainer):
resource_container.ResourceContainer.add_to_cache(
invoke_remote.remote, request_message)
invoke_remote.method_info = _MethodInfo(
name=name or api_method.__name__, path=path or api_method.__name__,
http_method=http_method or DEFAULT_HTTP_METHOD,
scopes=scopes, audiences=audiences,
allowed_client_ids=allowed_client_ids, auth_level=auth_level,
api_key_required=api_key_required, metric_costs=metric_costs,
use_request_uri=use_request_uri,
request_body_class=request_body_class,
request_params_class=request_params_class)
invoke_remote.__name__ = invoke_remote.method_info.name
return invoke_remote
endpoints_util.check_list_type(scopes, (basestring, endpoints_types.OAuth2Scope), 'scopes')
endpoints_util.check_list_type(allowed_client_ids, basestring,
'allowed_client_ids')
_CheckEnum(auth_level, AUTH_LEVEL, 'auth_level')
_CheckAudiences(audiences)
_CheckType(metric_costs, dict, 'metric_costs')
return apiserving_method_decorator |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'api_class'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'resource_name'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '39', '87']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_logger'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_AUTH_LEVEL_WARNING'}, {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': 'apiserving_api_decorator'}, {'id': '41', 'type': 'parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'api_class'}, {'id': '43', 'type': 'block', 'children': ['44', '53', '85']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '__classes'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'api_class'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'api_class'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'api_info'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_ApiInfo'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '64', '67', '70', '73', '76', '79', '82']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '__common_info'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'resource_name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'resource_name'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'audiences'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'audiences'}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'allowed_client_ids'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'auth_level'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'auth_level'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'api_key_required'}, {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'api_class'}, {'id': '87', 'type': 'return_statement', 'children': ['88']} | def api_class(self, resource_name=None, path=None, audiences=None,
scopes=None, allowed_client_ids=None, auth_level=None,
api_key_required=None):
if auth_level is not None:
_logger.warn(_AUTH_LEVEL_WARNING)
def apiserving_api_decorator(api_class):
self.__classes.append(api_class)
api_class.api_info = _ApiInfo(
self.__common_info, resource_name=resource_name,
path=path, audiences=audiences, scopes=scopes,
allowed_client_ids=allowed_client_ids, auth_level=auth_level,
api_key_required=api_key_required)
return api_class
return apiserving_api_decorator |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__field_to_subfields'}, {'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', '21', '25', '74']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '16']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'MessageField'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'list', 'children': ['19'], 'value': '[[field]]'}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[field]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '45']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'subfield'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '37']}; {'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': 'field'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'message_type'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'all_fields'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'lambda', 'children': ['40', '42']}; {'id': '40', 'type': 'lambda_parameters', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'number'}, {'id': '45', 'type': 'block', 'children': ['46', '55']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'subfield_results'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '__field_to_subfields'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'subfield'}, {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'subfields_list'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'subfield_results'}; {'id': '58', 'type': 'block', 'children': ['59', '67']}, {'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': 'subfields_list'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'field'}, {'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': 'result'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'subfields_list'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'result'} | def __field_to_subfields(self, field):
if not isinstance(field, messages.MessageField):
return [[field]]
result = []
for subfield in sorted(field.message_type.all_fields(),
key=lambda f: f.number):
subfield_results = self.__field_to_subfields(subfield)
for subfields_list in subfield_results:
subfields_list.insert(0, field)
result.append(subfields_list)
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__schemas_descriptor'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '175', '209']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '25']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'schema_key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'schema_value'}; {'id': '14', 'type': 'call', 'children': ['15', '24']}, {'id': '15', 'type': 'attribute', 'children': ['16', '23']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__parser'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'schemas'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '34', '38', '146', '166']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'field_keys'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'schema_value'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key_result'}, {'id': '37', 'type': 'dictionary', 'children': []}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'field_keys'}; {'id': '42', 'type': 'block', 'children': ['43', '55']}, {'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': 'key_result'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'schema_value'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'for_statement', 'children': ['56', '59', '66']}; {'id': '56', 'type': 'pattern_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'prop_key'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'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': 'schema_value'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '134']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71', '95']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'enum'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '71', 'type': 'block', 'children': ['72', '81']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'num_enums'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'enum'"}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '90']}, {'id': '83', 'type': 'subscript', 'children': ['84', '89']}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key_result'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'prop_key'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'enumDescriptions'"}; {'id': '90', 'type': 'parenthesized_expression', 'children': ['91']}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '94'], 'value': '*'}; {'id': '92', 'type': 'list', 'children': ['93'], 'value': "['']"}, {'id': '93', 'type': 'string', 'children': [], 'value': "''"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'num_enums'}, {'id': '95', 'type': 'elif_clause', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'in'}, {'id': '97', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '109', '121']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '108'], 'value': '=='}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '108', 'type': 'string', 'children': [], 'value': "'boolean'"}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'default'"}, {'id': '115', 'type': 'conditional_expression', 'children': ['116', '117', '120'], 'value': 'if'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'true'"}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'false'"}, {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '143']}; {'id': '136', 'type': 'attribute', 'children': ['137', '142']}, {'id': '137', 'type': 'subscript', 'children': ['138', '141']}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'key_result'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'prop_key'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'required'"}, {'id': '145', 'type': 'None', 'children': []}; {'id': '146', 'type': 'for_statement', 'children': ['147', '148', '152']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '148', 'type': 'tuple', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '150', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '151', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'in'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'field_keys'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'key_result'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'schema_value'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'key_result'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'schema_key'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'key_result'}, {'id': '175', 'type': 'for_statement', 'children': ['176', '177', '182']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'schema_value'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '181', 'type': 'argument_list', 'children': []}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'for_statement', 'children': ['184', '185', '190']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'field_value'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'schema_value'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'if_statement', 'children': ['192', '197']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'field_value'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'if_statement', 'children': ['199', '202']}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'in'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'$ref'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'field_value'}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '208']}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'field_value'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '208', 'type': 'string', 'children': [], 'value': "'object'"}, {'id': '209', 'type': 'return_statement', 'children': ['210']} | def __schemas_descriptor(self):
result = {}
for schema_key, schema_value in self.__parser.schemas().iteritems():
field_keys = schema_value.keys()
key_result = {}
if 'properties' in field_keys:
key_result['properties'] = schema_value['properties'].copy()
for prop_key, prop_value in schema_value['properties'].iteritems():
if 'enum' in prop_value:
num_enums = len(prop_value['enum'])
key_result['properties'][prop_key]['enumDescriptions'] = (
[''] * num_enums)
elif 'default' in prop_value:
if prop_value.get('type') == 'boolean':
prop_value['default'] = 'true' if prop_value['default'] else 'false'
else:
prop_value['default'] = str(prop_value['default'])
key_result['properties'][prop_key].pop('required', None)
for key in ('type', 'id', 'description'):
if key in field_keys:
key_result[key] = schema_value[key]
if key_result:
result[schema_key] = key_result
for schema_value in result.itervalues():
for field_value in schema_value.itervalues():
if isinstance(field_value, dict):
if '$ref' in field_value:
field_value['type'] = 'object'
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__discovery_doc_descriptor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '19', '31', '37', '56', '65', '75', '86', '170', '174', '178', '182', '191', '195', '376', '398', '407', '416', '424', '433']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'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': '__get_merged_api_info'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_descriptor_defaults'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'hostname'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '47']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '41'], 'value': 'and'}, {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'description'}, {'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': 'services'}; {'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': 'description'}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'description'}, {'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': 'descriptor'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'parameters'"}; {'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': '__standard_parameters_descriptor'}; {'id': '74', 'type': 'argument_list', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'auth'"}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '__standard_auth_descriptor'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90', '123']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '90', 'type': 'block', 'children': ['91', '101', '111']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'ownerDomain'"}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'ownerName'"}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'owner_name'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'packagePath'"}; {'id': '116', 'type': 'boolean_operator', 'children': ['117', '122'], 'value': 'or'}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'namespace'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'package_path'}; {'id': '122', 'type': 'string', 'children': [], 'value': "''"}, {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125', '140', '155']}, {'id': '125', 'type': 'if_statement', 'children': ['126', '131']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': 'is'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}; {'id': '130', 'type': 'None', 'children': []}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'ownerDomain'"}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'owner_domain'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '146']}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': 'is'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'owner_name'}, {'id': '145', 'type': 'None', 'children': []}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'ownerName'"}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'owner_name'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '161']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': 'is'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'package_path'}; {'id': '160', 'type': 'None', 'children': []}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '167']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'packagePath'"}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'package_path'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '173', 'type': 'dictionary', 'children': []}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}, {'id': '177', 'type': 'dictionary', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '181', 'type': 'dictionary', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'resource_index'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'resource_map'}; {'id': '194', 'type': 'dictionary', 'children': []}, {'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '198', 'type': 'block', 'children': ['199', '207']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'remote_methods'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'all_remote_methods'}; {'id': '206', 'type': 'argument_list', 'children': []}, {'id': '207', 'type': 'for_statement', 'children': ['208', '211', '216']}; {'id': '208', 'type': 'pattern_list', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_name'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'remote_methods'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '215', 'type': 'argument_list', 'children': []}; {'id': '216', 'type': 'block', 'children': ['217', '226', '232', '243', '254', '263', '272', '303', '311', '345']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'method_info'"}, {'id': '225', 'type': 'None', 'children': []}; {'id': '226', 'type': 'if_statement', 'children': ['227', '230']}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'is'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '229', 'type': 'None', 'children': []}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'continue_statement', 'children': []}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'get_path'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'api_info'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'api_info'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'canonical_method_id'}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '_get_canonical_method_id'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'resource_path'}; {'id': '266', 'type': 'call', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': '_get_resource_path'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '272', 'type': 'if_statement', 'children': ['273', '276', '293']}, {'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': 'in'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}; {'id': '276', 'type': 'block', 'children': ['277']}, {'id': '277', 'type': 'raise_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'api_exceptions'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'ApiConfigurationError'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '%'}; {'id': '284', 'type': 'string', 'children': [], 'value': "'Method %s used multiple times, in classes %s and %s'"}, {'id': '285', 'type': 'tuple', 'children': ['286', '287', '290']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '293', 'type': 'else_clause', 'children': ['294']}; {'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': 'method_collision_tracker'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '306', 'type': 'tuple', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'http_method'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '311', 'type': 'if_statement', 'children': ['312', '315', '335']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': 'in'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'raise_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'api_exceptions'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'ApiConfigurationError'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'binary_operator', 'children': ['323', '324'], 'value': '%'}, {'id': '323', 'type': 'string', 'children': [], 'value': '\'%s path "%s" used multiple times, in classes %s and %s\''}; {'id': '324', 'type': 'tuple', 'children': ['325', '328', '329', '332']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'http_method'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '335', 'type': 'else_clause', 'children': ['336']}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'assignment', 'children': ['339', '342']}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '345', 'type': 'if_statement', 'children': ['346', '347', '361']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'resource_path'}, {'id': '347', 'type': 'block', 'children': ['348']}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'call', 'children': ['350', '357']}; {'id': '350', 'type': 'attribute', 'children': ['351', '356']}, {'id': '351', 'type': 'subscript', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'resource_index'}, {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'resource_path'}, {'id': '355', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'tuple', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}, {'id': '361', 'type': 'else_clause', 'children': ['362']}; {'id': '362', 'type': 'block', 'children': ['363']}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'assignment', 'children': ['365', '368']}, {'id': '365', 'type': 'subscript', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'canonical_method_id'}; {'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': '__method_descriptor'}; {'id': '372', 'type': 'argument_list', 'children': ['373', '374', '375']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}; {'id': '376', 'type': 'for_statement', 'children': ['377', '380', '385']}, {'id': '377', 'type': 'pattern_list', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'resource'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'resource_methods'}; {'id': '380', 'type': 'call', 'children': ['381', '384']}, {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'resource_index'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '384', 'type': 'argument_list', 'children': []}, {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'assignment', 'children': ['388', '391']}; {'id': '388', 'type': 'subscript', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'resource_map'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'resource'}, {'id': '391', 'type': 'call', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': '__resource_descriptor'}, {'id': '395', 'type': 'argument_list', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'resource'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'resource_methods'}; {'id': '398', 'type': 'if_statement', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'method_map'}; {'id': '400', 'type': 'block', 'children': ['401']}, {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'assignment', 'children': ['403', '406']}, {'id': '403', 'type': 'subscript', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '405', 'type': 'string', 'children': [], 'value': "'methods'"}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '407', 'type': 'if_statement', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'resource_map'}, {'id': '409', 'type': 'block', 'children': ['410']}; {'id': '410', 'type': 'expression_statement', 'children': ['411']}, {'id': '411', 'type': 'assignment', 'children': ['412', '415']}; {'id': '412', 'type': 'subscript', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '414', 'type': 'string', 'children': [], 'value': "'resources'"}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'resource_map'}; {'id': '416', 'type': 'expression_statement', 'children': ['417']}, {'id': '417', 'type': 'assignment', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'schemas'}, {'id': '419', 'type': 'call', 'children': ['420', '423']}; {'id': '420', 'type': 'attribute', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '422', 'type': 'identifier', 'children': [], 'value': '__schemas_descriptor'}, {'id': '423', 'type': 'argument_list', 'children': []}; {'id': '424', 'type': 'if_statement', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'schemas'}; {'id': '426', 'type': 'block', 'children': ['427']}, {'id': '427', 'type': 'expression_statement', 'children': ['428']}; {'id': '428', 'type': 'assignment', 'children': ['429', '432']}, {'id': '429', 'type': 'subscript', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '431', 'type': 'string', 'children': [], 'value': "'schemas'"}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'schemas'}, {'id': '433', 'type': 'return_statement', 'children': ['434']} | def __discovery_doc_descriptor(self, services, hostname=None):
merged_api_info = self.__get_merged_api_info(services)
descriptor = self.get_descriptor_defaults(merged_api_info,
hostname=hostname)
description = merged_api_info.description
if not description and len(services) == 1:
description = services[0].__doc__
if description:
descriptor['description'] = description
descriptor['parameters'] = self.__standard_parameters_descriptor()
descriptor['auth'] = self.__standard_auth_descriptor(services)
if merged_api_info.namespace:
descriptor['ownerDomain'] = merged_api_info.namespace.owner_domain
descriptor['ownerName'] = merged_api_info.namespace.owner_name
descriptor['packagePath'] = merged_api_info.namespace.package_path or ''
else:
if merged_api_info.owner_domain is not None:
descriptor['ownerDomain'] = merged_api_info.owner_domain
if merged_api_info.owner_name is not None:
descriptor['ownerName'] = merged_api_info.owner_name
if merged_api_info.package_path is not None:
descriptor['packagePath'] = merged_api_info.package_path
method_map = {}
method_collision_tracker = {}
rest_collision_tracker = {}
resource_index = collections.defaultdict(list)
resource_map = {}
for service in services:
remote_methods = service.all_remote_methods()
for protorpc_meth_name, protorpc_meth_info in remote_methods.iteritems():
method_info = getattr(protorpc_meth_info, 'method_info', None)
if method_info is None:
continue
path = method_info.get_path(service.api_info)
method_id = method_info.method_id(service.api_info)
canonical_method_id = self._get_canonical_method_id(method_id)
resource_path = self._get_resource_path(method_id)
if method_id in method_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'Method %s used multiple times, in classes %s and %s' %
(method_id, method_collision_tracker[method_id],
service.__name__))
else:
method_collision_tracker[method_id] = service.__name__
rest_identifier = (method_info.http_method, path)
if rest_identifier in rest_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'%s path "%s" used multiple times, in classes %s and %s' %
(method_info.http_method, path,
rest_collision_tracker[rest_identifier],
service.__name__))
else:
rest_collision_tracker[rest_identifier] = service.__name__
if resource_path:
resource_index[resource_path[0]].append((service, protorpc_meth_info))
else:
method_map[canonical_method_id] = self.__method_descriptor(
service, method_info, protorpc_meth_info)
for resource, resource_methods in resource_index.items():
resource_map[resource] = self.__resource_descriptor(resource,
resource_methods)
if method_map:
descriptor['methods'] = method_map
if resource_map:
descriptor['resources'] = resource_map
schemas = self.__schemas_descriptor()
if schemas:
descriptor['schemas'] = schemas
return descriptor |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__definitions_descriptor'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '123', '164']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '25']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'def_key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'def_value'}; {'id': '14', 'type': 'call', 'children': ['15', '24']}, {'id': '15', 'type': 'attribute', 'children': ['16', '23']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__parser'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'schemas'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34']}, {'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'or'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'def_value'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'def_value'}; {'id': '34', 'type': 'block', 'children': ['35', '39', '45', '58', '105', '117']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key_result'}; {'id': '38', 'type': 'dictionary', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'required_keys'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'def_value'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key_result'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'def_value'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'in'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'def_value'}; {'id': '62', 'type': 'block', 'children': ['63', '97']}, {'id': '63', 'type': 'for_statement', 'children': ['64', '67', '74']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'prop_key'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'def_value'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'if_statement', 'children': ['76', '85']}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '82'], 'value': 'and'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'in'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'required'"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'required_keys'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'prop_key'}, {'id': '93', 'type': 'delete_statement', 'children': ['94']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'required'"}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key_result'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'properties'"}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'def_value'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '105', 'type': 'if_statement', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'required_keys'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'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': 'key_result'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'required'"}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'required_keys'}, {'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': 'result'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'def_key'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'key_result'}, {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '130']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'def_value'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '138']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'def_value'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'itervalues'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'if_statement', 'children': ['140', '145']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '145', 'type': 'block', 'children': ['146', '157']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'in'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'$ref'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '156', 'type': 'string', 'children': [], 'value': "'object'"}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_add_def_paths'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '164', 'type': 'return_statement', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'} | def __definitions_descriptor(self):
result = {}
for def_key, def_value in self.__parser.schemas().iteritems():
if 'properties' in def_value or 'type' in def_value:
key_result = {}
required_keys = set()
if 'type' in def_value:
key_result['type'] = def_value['type']
if 'properties' in def_value:
for prop_key, prop_value in def_value['properties'].items():
if isinstance(prop_value, dict) and 'required' in prop_value:
required_keys.add(prop_key)
del prop_value['required']
key_result['properties'] = def_value['properties']
if required_keys:
key_result['required'] = sorted(required_keys)
result[def_key] = key_result
for def_value in result.itervalues():
for prop_value in def_value.itervalues():
if isinstance(prop_value, dict):
if '$ref' in prop_value:
prop_value['type'] = 'object'
self._add_def_paths(prop_value)
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__api_openapi_descriptor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'x_google_api_name'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '22', '37', '43', '62', '73', '84', '88', '92', '96', '343', '352', '360', '369', '375', '386', '395']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'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_merged_api_info'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'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': 'get_descriptor_defaults'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hostname'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x_google_api_name'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'x_google_api_name'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '53']}; {'id': '44', 'type': 'boolean_operator', 'children': ['45', '47'], 'value': 'and'}, {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '52'], 'value': '=='}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '72']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '71', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'security_definitions'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '__security_definitions_descriptor'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'issuers'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '87', 'type': 'dictionary', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}, {'id': '91', 'type': 'dictionary', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '95', 'type': 'dictionary', 'children': []}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '99', 'type': 'block', 'children': ['100', '108']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'remote_methods'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'all_remote_methods'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '118']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_name'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'remote_methods'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119', '125', '134', '140', '151', '162', '184', '194', '205', '227', '239', '256', '287', '302']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'remote_methods'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_name'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'method_info'"}, {'id': '133', 'type': 'None', 'children': []}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '137', 'type': 'None', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'continue_statement', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'api_info'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'is_api_key_required'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'is_api_key_required'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'api_info'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'string', 'children': [], 'value': "'/{0}/{1}/{2}'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '173', '176']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'path_version'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'get_path'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'api_info'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'verb'}, {'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': 'method_info'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'http_method'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'if_statement', 'children': ['195', '198']}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'not'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'method_map'}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '204', 'type': 'dictionary', 'children': []}, {'id': '205', 'type': 'if_statement', 'children': ['206', '211']}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '208'], 'value': 'and'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'is_api_key_required'}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': 'not'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': '_API_KEY'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'security_definitions'}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'security_definitions'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': '_API_KEY'}, {'id': '217', 'type': 'dictionary', 'children': ['218', '221', '224']}; {'id': '218', 'type': 'pair', 'children': ['219', '220']}, {'id': '219', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '220', 'type': 'string', 'children': [], 'value': "'apiKey'"}, {'id': '221', 'type': 'pair', 'children': ['222', '223']}; {'id': '222', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '223', 'type': 'identifier', 'children': [], 'value': '_API_KEY_PARAM'}; {'id': '224', 'type': 'pair', 'children': ['225', '226']}, {'id': '225', 'type': 'string', 'children': [], 'value': "'in'"}; {'id': '226', 'type': 'string', 'children': [], 'value': "'query'"}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'operation_id'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '_construct_operation_id'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_name'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '246']}, {'id': '241', 'type': 'subscript', 'children': ['242', '245']}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'method_map'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'verb'}; {'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': '__method_descriptor'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253', '254', '255']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'operation_id'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'protorpc_meth_info'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'security_definitions'}; {'id': '256', 'type': 'if_statement', 'children': ['257', '260', '277']}, {'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': 'in'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}; {'id': '260', 'type': 'block', 'children': ['261']}, {'id': '261', 'type': 'raise_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'api_exceptions'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ApiConfigurationError'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '%'}; {'id': '268', 'type': 'string', 'children': [], 'value': "'Method %s used multiple times, in classes %s and %s'"}, {'id': '269', 'type': 'tuple', 'children': ['270', '271', '274']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'method_id'}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '277', 'type': 'else_clause', 'children': ['278']}; {'id': '278', 'type': 'block', 'children': ['279']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '284']}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'method_collision_tracker'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'method_id'}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '290', 'type': 'tuple', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'http_method'}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'method_info'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'get_path'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'api_info'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '306', '333']}, {'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'in'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}; {'id': '306', 'type': 'block', 'children': ['307']}, {'id': '307', 'type': 'raise_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'api_exceptions'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'ApiConfigurationError'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '315'], 'value': '%'}; {'id': '314', 'type': 'string', 'children': [], 'value': '\'%s path "%s" used multiple times, in classes %s and %s\''}, {'id': '315', 'type': 'tuple', 'children': ['316', '319', '327', '330']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'http_method'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'method_info'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'get_path'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'api_info'}, {'id': '327', 'type': 'subscript', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '333', 'type': 'else_clause', 'children': ['334']}; {'id': '334', 'type': 'block', 'children': ['335']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '340']}, {'id': '337', 'type': 'subscript', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'rest_collision_tracker'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'rest_identifier'}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '343', 'type': 'if_statement', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'method_map'}, {'id': '345', 'type': 'block', 'children': ['346']}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'assignment', 'children': ['348', '351']}; {'id': '348', 'type': 'subscript', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '350', 'type': 'string', 'children': [], 'value': "'paths'"}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'method_map'}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'definitions'}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': '__definitions_descriptor'}, {'id': '359', 'type': 'argument_list', 'children': []}; {'id': '360', 'type': 'if_statement', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'definitions'}; {'id': '362', 'type': 'block', 'children': ['363']}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'assignment', 'children': ['365', '368']}, {'id': '365', 'type': 'subscript', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '367', 'type': 'string', 'children': [], 'value': "'definitions'"}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'definitions'}, {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'assignment', 'children': ['371', '374']}, {'id': '371', 'type': 'subscript', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '373', 'type': 'string', 'children': [], 'value': "'securityDefinitions'"}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'security_definitions'}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}; {'id': '378', 'type': 'call', 'children': ['379', '382']}, {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': '__x_google_quota_definitions_descriptor'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'merged_api_info'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}; {'id': '386', 'type': 'if_statement', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}; {'id': '388', 'type': 'block', 'children': ['389']}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'assignment', 'children': ['391', '394']}, {'id': '391', 'type': 'subscript', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '393', 'type': 'string', 'children': [], 'value': "'x-google-management'"}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'limit_definitions'}, {'id': '395', 'type': 'return_statement', 'children': ['396']} | def __api_openapi_descriptor(self, services, hostname=None, x_google_api_name=False):
merged_api_info = self.__get_merged_api_info(services)
descriptor = self.get_descriptor_defaults(merged_api_info,
hostname=hostname,
x_google_api_name=x_google_api_name)
description = merged_api_info.description
if not description and len(services) == 1:
description = services[0].__doc__
if description:
descriptor['info']['description'] = description
security_definitions = self.__security_definitions_descriptor(
merged_api_info.issuers)
method_map = {}
method_collision_tracker = {}
rest_collision_tracker = {}
for service in services:
remote_methods = service.all_remote_methods()
for protorpc_meth_name in sorted(remote_methods.iterkeys()):
protorpc_meth_info = remote_methods[protorpc_meth_name]
method_info = getattr(protorpc_meth_info, 'method_info', None)
if method_info is None:
continue
method_id = method_info.method_id(service.api_info)
is_api_key_required = method_info.is_api_key_required(service.api_info)
path = '/{0}/{1}/{2}'.format(merged_api_info.name,
merged_api_info.path_version,
method_info.get_path(service.api_info))
verb = method_info.http_method.lower()
if path not in method_map:
method_map[path] = {}
if is_api_key_required and _API_KEY not in security_definitions:
security_definitions[_API_KEY] = {
'type': 'apiKey',
'name': _API_KEY_PARAM,
'in': 'query'
}
operation_id = self._construct_operation_id(
service.__name__, protorpc_meth_name)
method_map[path][verb] = self.__method_descriptor(
service, method_info, operation_id, protorpc_meth_info,
security_definitions)
if method_id in method_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'Method %s used multiple times, in classes %s and %s' %
(method_id, method_collision_tracker[method_id],
service.__name__))
else:
method_collision_tracker[method_id] = service.__name__
rest_identifier = (method_info.http_method,
method_info.get_path(service.api_info))
if rest_identifier in rest_collision_tracker:
raise api_exceptions.ApiConfigurationError(
'%s path "%s" used multiple times, in classes %s and %s' %
(method_info.http_method, method_info.get_path(service.api_info),
rest_collision_tracker[rest_identifier],
service.__name__))
else:
rest_collision_tracker[rest_identifier] = service.__name__
if method_map:
descriptor['paths'] = method_map
definitions = self.__definitions_descriptor()
if definitions:
descriptor['definitions'] = definitions
descriptor['securityDefinitions'] = security_definitions
limit_definitions = self.__x_google_quota_definitions_descriptor(
merged_api_info.limit_definitions)
if limit_definitions:
descriptor['x-google-management'] = limit_definitions
return descriptor |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__message_to_schema'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'message_type'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '26', '39', '43', '306', '312']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '__normalized_name'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'message_type'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '19', 'type': 'dictionary', 'children': ['20', '23']}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'object'"}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'message_type'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'message_type'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '__doc__'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '42', 'type': 'dictionary', 'children': []}, {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '50']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'message_type'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'all_fields'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '55', '59', '182', '225', '236', '272', '298']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '54', 'type': 'dictionary', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'id': '58', 'type': 'dictionary', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '68', '103']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '65'], 'value': '=='}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'MessageField'}; {'id': '68', 'type': 'block', 'children': ['69', '79', '90']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'field_type'}; {'id': '72', 'type': 'attribute', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'type_info'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'$ref'"}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'add_message'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'field_type'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'field_type'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'field_type'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '__doc__'}, {'id': '103', 'type': 'else_clause', 'children': ['104']}; {'id': '104', 'type': 'block', 'children': ['105', '122', '161', '169']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'schema_type'}; {'id': '108', 'type': 'call', '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': '__FIELD_TO_SCHEMA_TYPE_MAP'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '119']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '__DEFAULT_SCHEMA_TYPE'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '128']}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'schema_type'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '128', 'type': 'block', 'children': ['129', '133', '142']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'variant_map'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'schema_type'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'variant'"}, {'id': '141', 'type': 'None', 'children': []}; {'id': '142', 'type': 'if_statement', 'children': ['143', '146', '153']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'in'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'variant_map'}; {'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': 'schema_type'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'variant_map'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'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': 'schema_type'}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'variant_map'}; {'id': '160', 'type': 'None', 'children': []}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'type_info'}, {'id': '165', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'schema_type'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'schema_type'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'format'"}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'schema_type'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '191']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '188'], 'value': '=='}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'EnumField'}, {'id': '191', 'type': 'block', 'children': ['192', '213']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'sorted_enums'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '205']}; {'id': '198', 'type': 'list_comprehension', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'enum_info'}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'enum_info'}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '207', 'type': 'lambda', 'children': ['208', '210']}; {'id': '208', 'type': 'lambda_parameters', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'enum_info'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'enum_info'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'number'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '218']}, {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'type_info'}, {'id': '217', 'type': 'string', 'children': [], 'value': "'enum'"}; {'id': '218', 'type': 'list_comprehension', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'enum_info'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '222', 'type': 'for_in_clause', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'enum_info'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'sorted_enums'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'required'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '235']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'required'"}, {'id': '235', 'type': 'True', 'children': []}; {'id': '236', 'type': 'if_statement', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'if_statement', 'children': ['242', '250', '262']}; {'id': '242', 'type': 'comparison_operator', 'children': ['243', '247'], 'value': '=='}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'EnumField'}; {'id': '250', 'type': 'block', 'children': ['251']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '256']}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264']}; {'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': 'descriptor'}; {'id': '268', 'type': 'string', 'children': [], 'value': "'default'"}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '272', 'type': 'if_statement', 'children': ['273', '276', '289']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'repeated'}; {'id': '276', 'type': 'block', 'children': ['277', '283']}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '282']}, {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '281', 'type': 'string', 'children': [], 'value': "'items'"}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'type_info'}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '288']}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '287', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '288', 'type': 'string', 'children': [], 'value': "'array'"}, {'id': '289', 'type': 'else_clause', 'children': ['290']}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'descriptor'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'assignment', 'children': ['300', '305']}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'descriptor'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '311']}; {'id': '308', 'type': 'subscript', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '310', 'type': 'string', 'children': [], 'value': "'properties'"}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '312', 'type': 'return_statement', 'children': ['313']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'schema'} | def __message_to_schema(self, message_type):
name = self.__normalized_name(message_type)
schema = {
'id': name,
'type': 'object',
}
if message_type.__doc__:
schema['description'] = message_type.__doc__
properties = {}
for field in message_type.all_fields():
descriptor = {}
type_info = {}
if type(field) == messages.MessageField:
field_type = field.type().__class__
type_info['$ref'] = self.add_message(field_type)
if field_type.__doc__:
descriptor['description'] = field_type.__doc__
else:
schema_type = self.__FIELD_TO_SCHEMA_TYPE_MAP.get(
type(field), self.__DEFAULT_SCHEMA_TYPE)
if isinstance(schema_type, dict):
variant_map = schema_type
variant = getattr(field, 'variant', None)
if variant in variant_map:
schema_type = variant_map[variant]
else:
schema_type = variant_map[None]
type_info['type'] = schema_type[0]
if schema_type[1]:
type_info['format'] = schema_type[1]
if type(field) == messages.EnumField:
sorted_enums = sorted([enum_info for enum_info in field.type],
key=lambda enum_info: enum_info.number)
type_info['enum'] = [enum_info.name for enum_info in sorted_enums]
if field.required:
descriptor['required'] = True
if field.default:
if type(field) == messages.EnumField:
descriptor['default'] = str(field.default)
else:
descriptor['default'] = field.default
if field.repeated:
descriptor['items'] = type_info
descriptor['type'] = 'array'
else:
descriptor.update(type_info)
properties[field.name] = descriptor
schema['properties'] = properties
return schema |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'transform_parameter_value'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'parameter_config'}, {'id': '7', 'type': 'block', 'children': ['8', '35', '42', '84']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '27']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'transform_parameter_value'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '25', '26']}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'%s[%d]'"}; {'id': '22', 'type': 'tuple', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'parameter_config'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '31']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_get_parameter_conversion_entry'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'parameter_config'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '44', 'type': 'block', 'children': ['45', '52', '62']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '51']}, {'id': '47', 'type': 'pattern_list', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'validation_func'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'conversion_func'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'validation_func'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'validation_func'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'parameter_config'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'conversion_func'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'try_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'conversion_func'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '72', 'type': 'except_clause', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'raise_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'BasicTypeParameterError'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'} | def transform_parameter_value(parameter_name, value, parameter_config):
if isinstance(value, list):
return [transform_parameter_value('%s[%d]' % (parameter_name, index),
element, parameter_config)
for index, element in enumerate(value)]
entry = _get_parameter_conversion_entry(parameter_config)
if entry:
validation_func, conversion_func, type_name = entry
if validation_func:
validation_func(parameter_name, value, parameter_config)
if conversion_func:
try:
return conversion_func(value)
except ValueError:
raise errors.BasicTypeParameterError(parameter_name, value, type_name)
return value |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_conf_from'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ModuleConfig'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'CONF_SPEC'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'depth'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '17', 'type': 'block', 'children': ['18', '40', '79', '182']}; {'id': '18', 'type': 'for_statement', 'children': ['19', '22', '28']}, {'id': '19', 'type': 'pattern_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'default_value'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_get_key_from_module'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'default_value'}; {'id': '40', 'type': 'try_statement', 'children': ['41', '56', '60']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'filtered_apps'}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'apps'"}; {'id': '52', 'type': 'if_clause', 'children': ['53']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'not'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'BLACKLIST'}; {'id': '56', 'type': 'except_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'pass_statement', 'children': []}; {'id': '60', 'type': 'except_clause', 'children': ['61', '65']}, {'id': '61', 'type': 'as_pattern', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '63', 'type': 'as_pattern_target', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'Error %s during loading %s'"}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'apps'"}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'filtered_apps'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'try_statement', 'children': ['84', '175']}; {'id': '84', 'type': 'block', 'children': ['85', '92']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'app_module'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'import_module'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '!='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'app_module'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '96', 'type': 'block', 'children': ['97', '104']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'app_module'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_get_correct_module'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'app_module'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '<'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'depth'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '108', 'type': 'block', 'children': ['109', '121']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'mod_conf'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'extract_conf_from'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'app_module'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'for_statement', 'children': ['122', '125', '131']}; {'id': '122', 'type': 'pattern_list', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'mod_conf'}, {'id': '131', 'type': 'block', 'children': ['132', '138']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '=='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'config'"}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'continue_statement', 'children': []}; {'id': '138', 'type': 'if_statement', 'children': ['139', '144', '154']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '154', 'type': 'elif_clause', 'children': ['155', '162']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '159', 'type': 'tuple', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '175', 'type': 'except_clause', 'children': ['176', '180']}; {'id': '176', 'type': 'as_pattern', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '178', 'type': 'as_pattern_target', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'pass_statement', 'children': []}; {'id': '182', 'type': 'return_statement', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'conf'} | def extract_conf_from(mod, conf=ModuleConfig(CONF_SPEC), depth=0, max_depth=2):
for key, default_value in six.iteritems(conf):
conf[key] = _get_key_from_module(mod, key, default_value)
try:
filtered_apps = [app for app in conf['apps'] if app not in BLACKLIST]
except TypeError:
pass
except Exception as e:
warnings.warn('Error %s during loading %s' % (e, conf['apps']))
for app in filtered_apps:
try:
app_module = import_module(app)
if app_module != mod:
app_module = _get_correct_module(app_module)
if depth < max_depth:
mod_conf = extract_conf_from(app_module, depth=depth+1)
for k, v in six.iteritems(mod_conf):
if k == 'config':
continue
if isinstance(v, dict):
conf[k].update(v)
elif isinstance(v, (list, tuple)):
conf[k] = merge(conf[k], v)
except Exception as e:
pass
return conf |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_region'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '40', '54', '63', '72', '101', '105', '179', '186', '224']}; {'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': 'request'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '27', 'type': 'block', 'children': ['28', '34']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'query_string'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"GET"'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '47']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'_feincms_extra_context'"}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_feincms_extra_context'}, {'id': '53', 'type': 'dictionary', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}, {'id': '57', 'type': 'conditional_expression', 'children': ['58', '61', '62'], 'value': 'if'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'render_region'}; {'id': '66', 'type': 'conditional_expression', 'children': ['67', '70', '71'], 'value': 'if'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '87']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'request_processors'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'try_statement', 'children': ['89', '98']}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '98', 'type': 'except_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'pass_statement', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '104', 'type': 'dictionary', 'children': []}, {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '120']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'all_of_type'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_feincms_content_types_with_process'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'try_statement', 'children': ['122', '135', '138']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'view'}, {'id': '135', 'type': 'except_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'pass_statement', 'children': []}; {'id': '138', 'type': 'else_clause', 'children': ['139']}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'if_statement', 'children': ['141', '149', '169']}, {'id': '141', 'type': 'not_operator', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '149', 'type': 'block', 'children': ['150', '156']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'fe_identifier'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'content'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'r'}, {'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', '178']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'fe_identifier'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '179', 'type': 'import_from_statement', 'children': ['180', '184']}; {'id': '180', 'type': 'dotted_name', 'children': ['181', '182', '183']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'leonardo'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'templatetags'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'leonardo_tags'}; {'id': '184', 'type': 'dotted_name', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': '_render_content'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'region_content'}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'string', 'children': [], 'value': "''"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '193', 'type': 'generator_expression', 'children': ['194', '215']}; {'id': '194', 'type': 'conditional_expression', 'children': ['195', '200', '205'], 'value': 'if'}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'fe_identifier'}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '204'], 'value': 'in'}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'fe_identifier'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': '_render_content'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209', '212']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '214', 'type': 'dictionary', 'children': []}, {'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'leonardo_page'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'render_region'}; {'id': '224', 'type': 'return_statement', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'region_content'} | def render_region(widget=None, request=None, view=None,
page=None, region=None):
if not isinstance(request, dict):
request.query_string = None
request.method = "GET"
if not hasattr(request, '_feincms_extra_context'):
request._feincms_extra_context = {}
leonardo_page = widget.parent if widget else page
render_region = widget.region if widget else region
for fn in reversed(list(leonardo_page.request_processors.values())):
try:
r = fn(leonardo_page, request)
except:
pass
contents = {}
for content in leonardo_page.content.all_of_type(tuple(
leonardo_page._feincms_content_types_with_process)):
try:
r = content.process(request, view=view)
except:
pass
else:
if not isinstance(r, six.string_types):
r.render()
contents[content.fe_identifier] = getattr(r, 'content', r)
else:
contents[content.fe_identifier] = r
from leonardo.templatetags.leonardo_tags import _render_content
region_content = ''.join(
contents[content.fe_identifier] if content.fe_identifier in contents else _render_content(
content, request=request, context={})
for content in getattr(leonardo_page.content, render_region))
return region_content |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_ajax_method'}, {'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': 'method'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '39', '47', '55', '68', '80', '314']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '17']}, {'id': '13', 'type': 'function_name', 'children': [], 'value': 'get_param'}; {'id': '14', 'type': 'parameters', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'try_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'POST'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'except_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'GET'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_param'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '46', 'type': 'string', 'children': [], 'value': '"widget_id"'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_param'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"class_name"'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'widget_content'"}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'render_widget'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'region'"}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'render_region'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82', '124']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '82', 'type': 'block', 'children': ['83', '90']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_widget_from_id'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '90', 'type': 'try_statement', 'children': ['91', '100', '113']}, {'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': 'func'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '100', 'type': 'except_clause', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '107', 'type': 'string', 'children': [], 'value': '"exception"'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"%s method is not implmented on %s"'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '119', 'type': 'string', 'children': [], 'value': '"result"'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '124', 'type': 'elif_clause', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '126', 'type': 'block', 'children': ['127', '164']}, {'id': '127', 'type': 'try_statement', 'children': ['128', '142']}; {'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': 'cls'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'get_model'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'list_splat', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'class_name'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '142', 'type': 'except_clause', 'children': ['143', '147']}, {'id': '143', 'type': 'as_pattern', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '145', 'type': 'as_pattern_target', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '147', 'type': 'block', 'children': ['148', '157']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"exception"'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'JsonResponse'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '168', '276']}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '=='}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '167', 'type': 'string', 'children': [], 'value': '"render_preview"'}; {'id': '168', 'type': 'block', 'children': ['169', '181', '190']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'FormCls'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'modelform_factory'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '178', 'type': 'tuple', 'children': ['179', '180']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'pk'"}; {'id': '180', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'FormCls'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'POST'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '196', '260']}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'is_valid'}, {'id': '195', 'type': 'argument_list', 'children': []}; {'id': '196', 'type': 'block', 'children': ['197', '207', '213', '254']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'dictionary_splat', 'children': ['204']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'frontend_editing'}; {'id': '212', 'type': 'False', 'children': []}, {'id': '213', 'type': 'try_statement', 'children': ['214', '228', '246']}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'dictionary_splat', 'children': ['224']}; {'id': '224', 'type': 'dictionary', 'children': ['225']}, {'id': '225', 'type': 'pair', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'request'"}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '228', 'type': 'except_clause', 'children': ['229', '233']}, {'id': '229', 'type': 'as_pattern', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '231', 'type': 'as_pattern_target', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '238', 'type': 'string', 'children': [], 'value': "'result'"}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'handle_exception'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '253']}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'result'"}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '259']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}, {'id': '261', 'type': 'block', 'children': ['262', '270']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '267']}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'result'"}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '275']}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'widget_id'}; {'id': '276', 'type': 'else_clause', 'children': ['277']}, {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'try_statement', 'children': ['279', '288', '303']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '285', 'type': 'argument_list', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '288', 'type': 'except_clause', 'children': ['289', '293']}, {'id': '289', 'type': 'as_pattern', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '291', 'type': 'as_pattern_target', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '293', 'type': 'block', 'children': ['294']}; {'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': 'response'}; {'id': '298', 'type': 'string', 'children': [], 'value': '"exception"'}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '303', 'type': 'else_clause', 'children': ['304']}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '310']}, {'id': '307', 'type': 'subscript', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '309', 'type': 'string', 'children': [], 'value': '"result"'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '314', 'type': 'return_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'JsonResponse'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'data'} | def handle_ajax_method(self, request, method):
response = {}
def get_param(request, name):
try:
return request.POST[name]
except KeyError:
return request.GET.get(name, None)
widget_id = get_param(request, "widget_id")
class_name = get_param(request, "class_name")
if method in 'widget_content':
return self.render_widget(request, widget_id)
if method == 'region':
return self.render_region(request)
if widget_id:
widget = get_widget_from_id(widget_id)
try:
func = getattr(widget, method)
except AttributeError:
response["exception"] = "%s method is not implmented on %s" % (
method, widget)
else:
response["result"] = func(request)
elif class_name:
try:
cls = get_model(*class_name.split('.'))
except Exception as e:
response["exception"] = str(e)
return JsonResponse(data=response)
if method == "render_preview":
FormCls = modelform_factory(cls, exclude=('pk', 'id'))
form = FormCls(request.POST)
if form.is_valid():
widget = cls(**form.cleaned_data)
request.frontend_editing = False
try:
content = widget.render(**{'request': request})
except Exception as e:
response['result'] = widget.handle_exception(request, e)
else:
response['result'] = content
response['id'] = widget_id
else:
response['result'] = form.errors
response['id'] = widget_id
else:
try:
func = getattr(cls, method)
except Exception as e:
response["exception"] = str(e)
else:
response["result"] = func(request)
return JsonResponse(data=response) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ajax_upload'}, {'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': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'folder_id'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '25', '32', '36', '74', '100']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'mimetype'}, {'id': '13', 'type': 'conditional_expression', 'children': ['14', '15', '20'], 'value': 'if'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"application/json"'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'is_ajax'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'string', 'children': [], 'value': '"text/html"'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'content_type_key'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'content_type'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'response_params'}; {'id': '28', 'type': 'dictionary', 'children': ['29']}, {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'content_type_key'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'mimetype'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'folder'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'folder_id'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'try_statement', 'children': ['40', '54']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'folder'}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'Folder'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'folder_id'}; {'id': '54', 'type': 'except_clause', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Folder'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '72']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'dictionary', 'children': ['69']}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'error'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'NO_FOLDER_ERROR'}; {'id': '72', 'type': 'dictionary_splat', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'response_params'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '84']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'and'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'folder'}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'folder'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'has_add_children_permission'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '98']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'dictionary', 'children': ['95']}, {'id': '95', 'type': 'pair', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'error'"}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'NO_PERMISSIONS_FOR_FOLDER'}; {'id': '98', 'type': 'dictionary_splat', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'response_params'}; {'id': '100', 'type': 'try_statement', 'children': ['101', '312']}, {'id': '101', 'type': 'block', 'children': ['102', '134', '173', '194']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '111', '122']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '110'], 'value': '=='}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'FILES'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '118']}; {'id': '114', 'type': 'pattern_list', 'children': ['115', '116', '117']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'upload'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'is_raw'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'handle_request_files_upload'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '122', 'type': 'else_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '130']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'upload'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'is_raw'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'handle_upload'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '134', 'type': 'for_statement', 'children': ['135', '136', '139']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'filer_class'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'media_settings'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'MEDIA_FILE_MODELS'}, {'id': '139', 'type': 'block', 'children': ['140', '147']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'FileSubClass'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'load_object'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'filer_class'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '156']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'FileSubClass'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'matches_file_type'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'upload'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '156', 'type': 'block', 'children': ['157', '172']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'FileForm'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'modelform_factory'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '166']}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'FileSubClass'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '168', 'type': 'tuple', 'children': ['169', '170', '171']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'original_filename'"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'owner'"}, {'id': '171', 'type': 'string', 'children': [], 'value': "'file'"}; {'id': '172', 'type': 'break_statement', 'children': []}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'uploadform'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'FileForm'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '190']}, {'id': '179', 'type': 'dictionary', 'children': ['180', '183']}; {'id': '180', 'type': 'pair', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'original_filename'"}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '183', 'type': 'pair', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'owner'"}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '190', 'type': 'dictionary', 'children': ['191']}, {'id': '191', 'type': 'pair', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': "'file'"}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'upload'}; {'id': '194', 'type': 'if_statement', 'children': ['195', '200', '269']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'uploadform'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'is_valid'}, {'id': '199', 'type': 'argument_list', 'children': []}; {'id': '200', 'type': 'block', 'children': ['201', '212', '220', '226', '232', '257']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'uploadform'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'commit'}, {'id': '211', 'type': 'False', 'children': []}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'is_public'}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'MEDIA_IS_PUBLIC_DEFAULT'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'folder'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'folder'}; {'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': 'file_obj'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'save'}, {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'json_response'}, {'id': '235', 'type': 'dictionary', 'children': ['236', '243', '246', '252']}; {'id': '236', 'type': 'pair', 'children': ['237', '238']}, {'id': '237', 'type': 'string', 'children': [], 'value': "'thumbnail'"}; {'id': '238', 'type': 'subscript', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'file_obj'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'icons'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'32'"}, {'id': '243', 'type': 'pair', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'alt_text'"}, {'id': '245', 'type': 'string', 'children': [], 'value': "''"}; {'id': '246', 'type': 'pair', 'children': ['247', '248']}, {'id': '247', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '252', 'type': 'pair', 'children': ['253', '254']}, {'id': '253', 'type': 'string', 'children': [], 'value': "'file_id'"}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'file_obj'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '257', 'type': 'return_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '267']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'json_response'}, {'id': '267', 'type': 'dictionary_splat', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'response_params'}, {'id': '269', 'type': 'else_clause', 'children': ['270']}; {'id': '270', 'type': 'block', 'children': ['271', '304']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'form_errors'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': "'; '"}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'list_comprehension', 'children': ['280', '290']}; {'id': '280', 'type': 'binary_operator', 'children': ['281', '282'], 'value': '%'}, {'id': '281', 'type': 'string', 'children': [], 'value': "'%s: %s'"}; {'id': '282', 'type': 'tuple', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '284', 'type': 'call', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '290', 'type': 'for_in_clause', 'children': ['291', '294']}, {'id': '291', 'type': 'pattern_list', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '296', 'type': 'argument_list', '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': 'uploadform'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'raise_statement', 'children': ['305']}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'UploadException'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '%'}, {'id': '309', 'type': 'string', 'children': [], 'value': '"AJAX request not valid: form invalid \'%s\'"'}; {'id': '310', 'type': 'tuple', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'form_errors'}; {'id': '312', 'type': 'except_clause', 'children': ['313', '317']}, {'id': '313', 'type': 'as_pattern', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'UploadException'}, {'id': '315', 'type': 'as_pattern_target', 'children': ['316']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '334']}; {'id': '322', 'type': 'call', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '326', 'type': 'argument_list', 'children': ['327']}, {'id': '327', 'type': 'dictionary', 'children': ['328']}; {'id': '328', 'type': 'pair', 'children': ['329', '330']}, {'id': '329', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '334', 'type': 'dictionary_splat', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'response_params'} | def ajax_upload(self, request, folder_id=None):
mimetype = "application/json" if request.is_ajax() else "text/html"
content_type_key = 'content_type'
response_params = {content_type_key: mimetype}
folder = None
if folder_id:
try:
folder = Folder.objects.get(pk=folder_id)
except Folder.DoesNotExist:
return HttpResponse(json.dumps({'error': NO_FOLDER_ERROR}),
**response_params)
if folder and not folder.has_add_children_permission(request):
return HttpResponse(
json.dumps({'error': NO_PERMISSIONS_FOR_FOLDER}),
**response_params)
try:
if len(request.FILES) == 1:
upload, filename, is_raw = handle_request_files_upload(request)
else:
upload, filename, is_raw = handle_upload(request)
for filer_class in media_settings.MEDIA_FILE_MODELS:
FileSubClass = load_object(filer_class)
if FileSubClass.matches_file_type(filename, upload, request):
FileForm = modelform_factory(
model=FileSubClass,
fields=('original_filename', 'owner', 'file')
)
break
uploadform = FileForm({'original_filename': filename,
'owner': request.user.pk},
{'file': upload})
if uploadform.is_valid():
file_obj = uploadform.save(commit=False)
file_obj.is_public = settings.MEDIA_IS_PUBLIC_DEFAULT
file_obj.folder = folder
file_obj.save()
json_response = {
'thumbnail': file_obj.icons['32'],
'alt_text': '',
'label': str(file_obj),
'file_id': file_obj.pk,
}
return HttpResponse(json.dumps(json_response),
**response_params)
else:
form_errors = '; '.join(['%s: %s' % (
field,
', '.join(errors)) for field, errors in list(uploadform.errors.items())
])
raise UploadException(
"AJAX request not valid: form invalid '%s'" % (form_errors,))
except UploadException as e:
return HttpResponse(json.dumps({'error': str(e)}),
**response_params) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '20', '30', '315']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ignore_patterns'}, {'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15', '16', '17', '18', '19'], 'value': "[\n '*.png', '*.jpg', '*.js', '*.gif', '*.ttf', '*.md', '*.rst',\n '*.svg']"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'*.png'"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'*.jpg'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'*.js'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'*.gif'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'*.ttf'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'*.md'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'*.rst'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'*.svg'"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'page_themes'}, {'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': 'PageTheme'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'finder'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_finders'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'for_statement', 'children': ['37', '40', '48']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'storage'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'finder'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ignore_patterns'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'page_themes'}; {'id': '52', 'type': 'block', 'children': ['53', '72']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'static_path'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'themes/{0}'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'subscript', 'children': ['62', '70']}; {'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': 't'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '70', 'type': 'unary_operator', 'children': ['71'], 'value': '-'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'static_path'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '76', 'type': 'block', 'children': ['77', '125', '157']}, {'id': '77', 'type': 'try_statement', 'children': ['78', '94', '104']}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'page_theme'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'PageTheme'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '94', 'type': 'except_clause', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'PageTheme'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'raise_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': '"Run sync_themes before this command"'}; {'id': '104', 'type': 'except_clause', 'children': ['105', '109']}, {'id': '105', 'type': 'as_pattern', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '107', 'type': 'as_pattern_target', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"Cannot load {} into database original error: {}"'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'skins_path'}; {'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': 'os'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'storage'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '152']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '152', 'type': 'slice', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'colon', 'children': []}, {'id': '155', 'type': 'unary_operator', 'children': ['156'], 'value': '-'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'for_statement', 'children': ['158', '162', '168']}; {'id': '158', 'type': 'pattern_list', 'children': ['159', '160', '161']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'dirpath'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'skins'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'skins_path'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'for_statement', 'children': ['170', '171', '181']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '171', 'type': 'list_comprehension', 'children': ['172', '173', '176']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'skins'}; {'id': '176', 'type': 'if_clause', 'children': ['177']}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'not'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': "['fonts']"}; {'id': '180', 'type': 'string', 'children': [], 'value': "'fonts'"}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'for_statement', 'children': ['183', '187', '201']}, {'id': '183', 'type': 'pattern_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'skin_dirpath'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'skins'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '198']}, {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dirpath'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '201', 'type': 'block', 'children': ['202', '227', '303', '309']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '207']}; {'id': '204', 'type': 'pattern_list', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'skin'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '207', 'type': 'call', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'PageColorScheme'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '217', '220']}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'theme'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'page_theme'}, {'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'skin'}; {'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '226', 'type': 'argument_list', 'children': []}, {'id': '227', 'type': 'for_statement', 'children': ['228', '229', '230']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'if_statement', 'children': ['232', '235', '267']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': 'in'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'styles'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'with_statement', 'children': ['237', '256']}, {'id': '237', 'type': 'with_clause', 'children': ['238']}; {'id': '238', 'type': 'with_item', 'children': ['239']}, {'id': '239', 'type': 'as_pattern', 'children': ['240', '254']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'codecs'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '251']}; {'id': '246', 'type': 'attribute', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'skin_dirpath'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '254', 'type': 'as_pattern_target', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'style_file'}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'styles'}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'style_file'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '266', 'type': 'argument_list', 'children': []}, {'id': '267', 'type': 'elif_clause', 'children': ['268', '271']}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'in'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'variables'"}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'with_statement', 'children': ['273', '292']}, {'id': '273', 'type': 'with_clause', 'children': ['274']}; {'id': '274', 'type': 'with_item', 'children': ['275']}, {'id': '275', 'type': 'as_pattern', 'children': ['276', '290']}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'codecs'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '287']}; {'id': '282', 'type': 'attribute', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '287', 'type': 'argument_list', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'skin_dirpath'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '290', 'type': 'as_pattern_target', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'variables_file'}; {'id': '292', 'type': 'block', 'children': ['293']}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '298', 'type': 'call', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'variables_file'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '302', 'type': 'argument_list', 'children': []}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'skin'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '308', 'type': 'argument_list', 'children': []}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'augmented_assignment', 'children': ['311', '314'], 'value': '+='}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'skins_updated'}; {'id': '314', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'augmented_assignment', 'children': ['317', '320'], 'value': '+='}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'page_themes_updated'}; {'id': '320', 'type': 'call', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'page_themes'} | def collect(self):
self.ignore_patterns = [
'*.png', '*.jpg', '*.js', '*.gif', '*.ttf', '*.md', '*.rst',
'*.svg']
page_themes = PageTheme.objects.all()
for finder in get_finders():
for path, storage in finder.list(self.ignore_patterns):
for t in page_themes:
static_path = 'themes/{0}'.format(t.name.split('/')[-1])
if static_path in path:
try:
page_theme = PageTheme.objects.get(id=t.id)
except PageTheme.DoesNotExist:
raise Exception(
"Run sync_themes before this command")
except Exception as e:
self.stdout.write(
"Cannot load {} into database original error: {}".format(t, e))
skins_path = os.path.join(
storage.path('/'.join(path.split('/')[0:-1])))
for dirpath, skins, filenames in os.walk(skins_path):
for skin in [s for s in skins if s not in ['fonts']]:
for skin_dirpath, skins, filenames in os.walk(os.path.join(dirpath, skin)):
skin, created = PageColorScheme.objects.get_or_create(
theme=page_theme, label=skin, name=skin.title())
for f in filenames:
if 'styles' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as style_file:
skin.styles = style_file.read()
elif 'variables' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as variables_file:
skin.variables = variables_file.read()
skin.save()
self.skins_updated += 1
self.page_themes_updated += len(page_themes) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'urlpatterns'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '189']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''load and decorate urls from all modules\n then store it as cached property for less loading\n '''"}; {'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': 'hasattr'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'_urlspatterns'"}, {'id': '15', 'type': 'block', 'children': ['16', '20', '90', '96', '183']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '25']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'leonardo'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'modules'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '31']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_leonardo_module'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '31', 'type': 'block', 'children': ['32', '39']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_conf_from_module'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '45']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'module_has_submodule'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'urls'"}, {'id': '45', 'type': 'block', 'children': ['46', '56']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'urls_mod'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'import_module'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'.urls'"}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'urls_mod'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'urlpatterns'"}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'if_statement', 'children': ['64', '67', '74']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'public'"}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'augmented_assignment', 'children': ['70', '71'], 'value': '+='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'urls_mod'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}, {'id': '75', 'type': 'block', 'children': ['76', '84']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_decorate_urlconf'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'urls_mod'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'require_auth'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'augmented_assignment', 'children': ['86', '87'], 'value': '+='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'urls_mod'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}; {'id': '90', 'type': 'import_from_statement', 'children': ['91', '94']}, {'id': '91', 'type': 'dotted_name', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'django'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '94', 'type': 'dotted_name', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '96', 'type': 'for_statement', 'children': ['97', '100', '111']}, {'id': '97', 'type': 'pattern_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'urls_conf'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '109', 'type': 'string', 'children': [], 'value': "'MODULE_URLS'"}; {'id': '110', 'type': 'dictionary', 'children': []}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'try_statement', 'children': ['113', '165']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '135']}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'is_public'"}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'augmented_assignment', 'children': ['121', '122', '123'], 'value': '+='}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}; {'id': '122', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "''"}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "r''"}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'include'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'urls_conf'}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137', '150']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_decorate_urlconf'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '149']}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "r''"}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'include'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'urls_conf'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'require_auth'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'augmented_assignment', 'children': ['152', '153'], 'value': '+='}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157']}; {'id': '156', 'type': 'string', 'children': [], 'value': "''"}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "r''"}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'include'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'urls_conf'}, {'id': '165', 'type': 'except_clause', 'children': ['166', '170']}; {'id': '166', 'type': 'as_pattern', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '168', 'type': 'as_pattern_target', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'raise_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'raised %s during loading %s'"}, {'id': '177', 'type': 'tuple', 'children': ['178', '182']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'urls_conf'}, {'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': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': '_urlpatterns'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'} | def urlpatterns(self):
'''load and decorate urls from all modules
then store it as cached property for less loading
'''
if not hasattr(self, '_urlspatterns'):
urlpatterns = []
for mod in leonardo.modules:
if is_leonardo_module(mod):
conf = get_conf_from_module(mod)
if module_has_submodule(mod, 'urls'):
urls_mod = import_module('.urls', mod.__name__)
if hasattr(urls_mod, 'urlpatterns'):
if conf['public']:
urlpatterns += urls_mod.urlpatterns
else:
_decorate_urlconf(urls_mod.urlpatterns,
require_auth)
urlpatterns += urls_mod.urlpatterns
from django.conf import settings
for urls_conf, conf in six.iteritems(getattr(settings, 'MODULE_URLS', {})):
try:
if conf['is_public']:
urlpatterns += \
patterns('',
url(r'', include(urls_conf)),
)
else:
_decorate_urlconf(
url(r'', include(urls_conf)),
require_auth)
urlpatterns += patterns('',
url(r'', include(urls_conf)))
except Exception as e:
raise Exception('raised %s during loading %s' %
(str(e), urls_conf))
self._urlpatterns = urlpatterns
return self._urlpatterns |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reverse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'viewname'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'urlconf'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '28', '35', '41', '47', '53', '300']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '21']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'urlconf'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'urlconf'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_urlconf'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'resolver'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_resolver'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'urlconf'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '40'], 'value': 'or'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'}; {'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': 'kwargs'}; {'id': '44', 'type': 'boolean_operator', 'children': ['45', '46'], 'value': 'or'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '46', 'type': 'dictionary', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_script_prefix'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'if_statement', 'children': ['54', '62', '67']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'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': 'viewname'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'viewname'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69', '78', '84', '90', '98', '102', '106', '289']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'viewname'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'view'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '95', 'type': 'slice', 'children': ['96', '97']}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'colon', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'resolved_path'}, {'id': '101', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ns_pattern'}, {'id': '105', 'type': 'string', 'children': [], 'value': "''"}; {'id': '106', 'type': 'while_statement', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '108', 'type': 'block', 'children': ['109', '117', '153']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'try_statement', 'children': ['118', '149']}; {'id': '118', 'type': 'block', 'children': ['119', '127']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'app_list'}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'resolver'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'app_dict'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '133', '138']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '130'], 'value': 'and'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'app_list'}, {'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': 'ns'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '138', 'type': 'elif_clause', 'children': ['139', '142']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'not'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'app_list'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'app_list'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '149', 'type': 'except_clause', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'pass_statement', 'children': []}, {'id': '153', 'type': 'try_statement', 'children': ['154', '178']}; {'id': '154', 'type': 'block', 'children': ['155', '165', '172']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'pattern_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'extra'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'resolver'}; {'id': '160', 'type': 'subscript', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'resolver'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'namespace_dict'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'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': 'resolved_path'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ns_pattern'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ns_pattern'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '178', 'type': 'except_clause', 'children': ['179', '183']}, {'id': '179', 'type': 'as_pattern', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '181', 'type': 'as_pattern_target', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '183', 'type': 'block', 'children': ['184', '263']}; {'id': '184', 'type': 'for_statement', 'children': ['185', '188', '200']}, {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'urlconf'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'attribute', 'children': ['194', '199']}; {'id': '194', 'type': 'subscript', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ApplicationWidget'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '_feincms_content_models'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ALL_APPS_CONFIG'}; {'id': '200', 'type': 'block', 'children': ['201', '210', '216', '224']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'partials'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'viewname'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'partials'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'partials'}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'partials'}, {'id': '221', 'type': 'slice', 'children': ['222', '223']}; {'id': '222', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '223', 'type': 'colon', 'children': []}; {'id': '224', 'type': 'if_statement', 'children': ['225', '236']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '235'], 'value': '=='}; {'id': '226', 'type': 'subscript', 'children': ['227', '233']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'urlconf'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '233', 'type': 'unary_operator', 'children': ['234'], 'value': '-'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'try_statement', 'children': ['238', '259']}; {'id': '238', 'type': 'block', 'children': ['239']}, {'id': '239', 'type': 'return_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'app_reverse'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '249', '250', '253', '256']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'partials'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'urlconf'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'current_app'}, {'id': '259', 'type': 'except_clause', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'pass_statement', 'children': []}, {'id': '263', 'type': 'if_statement', 'children': ['264', '265', '280']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'resolved_path'}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'raise_statement', 'children': ['267']}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '%'}, {'id': '271', 'type': 'string', 'children': [], 'value': '"%s is not a registered namespace inside \'%s\'"'}; {'id': '272', 'type': 'tuple', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'resolved_path'}; {'id': '280', 'type': 'else_clause', 'children': ['281']}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'raise_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'}, {'id': '287', 'type': 'string', 'children': [], 'value': '"%s is not a registered namespace"'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '289', 'type': 'if_statement', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ns_pattern'}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'resolver'}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'get_ns_resolver'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ns_pattern'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'resolver'}; {'id': '300', 'type': 'return_statement', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'iri_to_uri'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'resolver'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': '_reverse_with_prefix'}; {'id': '308', 'type': 'argument_list', 'children': ['309', '310', '311', '313']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '311', 'type': 'list_splat', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '313', 'type': 'dictionary_splat', 'children': ['314']} | def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
if not urlconf:
urlconf = get_urlconf()
resolver = get_resolver(urlconf)
args = args or []
kwargs = kwargs or {}
prefix = get_script_prefix()
if not isinstance(viewname, six.string_types):
view = viewname
else:
parts = viewname.split(':')
parts.reverse()
view = parts[0]
path = parts[1:]
resolved_path = []
ns_pattern = ''
while path:
ns = path.pop()
try:
app_list = resolver.app_dict[ns]
if current_app and current_app in app_list:
ns = current_app
elif ns not in app_list:
ns = app_list[0]
except KeyError:
pass
try:
extra, resolver = resolver.namespace_dict[ns]
resolved_path.append(ns)
ns_pattern = ns_pattern + extra
except KeyError as key:
for urlconf, config in six.iteritems(
ApplicationWidget._feincms_content_models[0].ALL_APPS_CONFIG):
partials = viewname.split(':')
app = partials[0]
partials = partials[1:]
if urlconf.split(".")[-1] == app:
try:
return app_reverse(
':'.join(partials),
urlconf, args=args, kwargs=kwargs,
current_app=current_app)
except NoReverseMatch:
pass
if resolved_path:
raise NoReverseMatch(
"%s is not a registered namespace inside '%s'" %
(key, ':'.join(resolved_path)))
else:
raise NoReverseMatch("%s is not a registered namespace" %
key)
if ns_pattern:
resolver = get_ns_resolver(ns_pattern, resolver)
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_response'}, {'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': 'response'}, {'id': '7', 'type': 'block', 'children': ['8', '174']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '20']}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '15'], 'value': 'and'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_ajax'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'horizon'"}; {'id': '20', 'type': 'block', 'children': ['21', '29', '160']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'queued_msgs'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'horizon'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'async_messages'"}, {'id': '29', 'type': 'if_statement', 'children': ['30', '38']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '35'], 'value': '=='}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'http'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}; {'id': '38', 'type': 'block', 'children': ['39', '57', '65', '79', '130', '138', '142', '158']}, {'id': '39', 'type': 'for_statement', 'children': ['40', '44', '45']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'extra_tags'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'queued_msgs'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'django_messages'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'extra_tags'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'redirect_response'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'http'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cookie_keys'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'tuple', 'children': ['72', '73', '74', '75', '76', '77', '78']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'max_age'"}, {'id': '73', 'type': 'string', 'children': [], 'value': "'expires'"}; {'id': '74', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '75', 'type': 'string', 'children': [], 'value': "'domain'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'secure'"}, {'id': '77', 'type': 'string', 'children': [], 'value': "'httponly'"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'logout_reason'"}, {'id': '79', 'type': 'for_statement', 'children': ['80', '83', '91']}; {'id': '80', 'type': 'pattern_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cookie_name'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cookie'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'cookies'}, {'id': '91', 'type': 'block', 'children': ['92', '118']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cookie_kwargs'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'generator_expression', 'children': ['99', '102', '112']}, {'id': '99', 'type': 'tuple', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '102', 'type': 'for_in_clause', 'children': ['103', '106']}, {'id': '103', 'type': 'pattern_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cookie'}; {'id': '112', 'type': 'if_clause', 'children': ['113']}, {'id': '113', 'type': 'boolean_operator', 'children': ['114', '117'], 'value': 'and'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'in'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'cookie_keys'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'redirect_response'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'set_cookie'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'cookie_name'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cookie'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '128', 'type': 'dictionary_splat', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cookie_kwargs'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'redirect_response'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'X-Horizon-Location'"}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '137', 'type': 'string', 'children': [], 'value': "'location'"}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'upload_url_key'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'X-File-Upload-URL'"}; {'id': '142', 'type': 'if_statement', 'children': ['143', '146']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'in'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'upload_url_key'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'response'}; {'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': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'copy_headers'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'redirect_response'}, {'id': '155', 'type': 'tuple', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'upload_url_key'}, {'id': '157', 'type': 'string', 'children': [], 'value': "'X-Auth-Token'"}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'redirect_response'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'queued_msgs'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'X-Horizon-Messages'"}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'queued_msgs'}; {'id': '174', 'type': 'return_statement', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'response'} | def process_response(self, request, response):
if request.is_ajax() and hasattr(request, 'horizon'):
queued_msgs = request.horizon['async_messages']
if type(response) == http.HttpResponseRedirect:
for tag, message, extra_tags in queued_msgs:
getattr(django_messages, tag)(request, message, extra_tags)
redirect_response = http.HttpResponse()
cookie_keys = set(('max_age', 'expires', 'path', 'domain',
'secure', 'httponly', 'logout_reason'))
for cookie_name, cookie in six.iteritems(response.cookies):
cookie_kwargs = dict((
(key, value) for key, value in six.iteritems(cookie)
if key in cookie_keys and value
))
redirect_response.set_cookie(
cookie_name, cookie.value, **cookie_kwargs)
redirect_response['X-Horizon-Location'] = response['location']
upload_url_key = 'X-File-Upload-URL'
if upload_url_key in response:
self.copy_headers(response, redirect_response,
(upload_url_key, 'X-Auth-Token'))
return redirect_response
if queued_msgs:
response['X-Horizon-Messages'] = json.dumps(queued_msgs)
return response |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_exception'}, {'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': 'exception'}, {'id': '7', 'type': 'block', 'children': ['8', '182', '198']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '20']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '13', 'type': 'tuple', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'NotAuthorized'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'NotAuthenticated'}; {'id': '20', 'type': 'block', 'children': ['21', '27', '31', '68', '83', '98', '107', '120', '152', '180']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'auth_url'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'LOGIN_URL'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'if_statement', 'children': ['32', '39']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': 'in'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '36', 'type': 'tuple', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"POST"'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"PUT"'}, {'id': '39', 'type': 'block', 'children': ['40', '51']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'referrer'}, {'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': 'request'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'META'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'HTTP_REFERER'"}, {'id': '51', 'type': 'if_statement', 'children': ['52', '63']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'referrer'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'is_safe_url'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'referrer'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_host'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'next_url'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'referrer'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '71']}, {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'next_url'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'next_url'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'iri_to_uri'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_full_path'}; {'id': '82', 'type': 'argument_list', 'children': []}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87', '92']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '!='}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'auth_url'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'REDIRECT_FIELD_NAME'}; {'id': '92', 'type': 'else_clause', 'children': ['93']}, {'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': 'field_name'}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'login_url'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'build_absolute_uri'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'auth_url'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'redirect_to_login'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '117']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'login_url'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'login_url'}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'redirect_field_name'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '128']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'NotAuthorized'}; {'id': '128', 'type': 'block', 'children': ['129', '136', '145']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'logout_reason'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"Unauthorized. Please try logging in again."'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'add_logout_reason'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'logout_reason'}, {'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': 'response'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'delete_cookie'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'messages'"}; {'id': '152', 'type': 'if_statement', 'children': ['153', '158']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'is_ajax'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159', '170', '178']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'response_401'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'http'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '401'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'response_401'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'X-Horizon-Location'"}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'location'"}; {'id': '178', 'type': 'return_statement', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'response_401'}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '190']}, {'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': 'exception'}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'NotFound'}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'raise_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'http'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'Http404'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '206']}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'Http302'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'shortcuts'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'location'} | def process_exception(self, request, exception):
if isinstance(exception, (exceptions.NotAuthorized,
exceptions.NotAuthenticated)):
auth_url = settings.LOGIN_URL
next_url = None
if request.method in ("POST", "PUT"):
referrer = request.META.get('HTTP_REFERER')
if referrer and is_safe_url(referrer, request.get_host()):
next_url = referrer
if not next_url:
next_url = iri_to_uri(request.get_full_path())
if next_url != auth_url:
field_name = REDIRECT_FIELD_NAME
else:
field_name = None
login_url = request.build_absolute_uri(auth_url)
response = redirect_to_login(next_url, login_url=login_url,
redirect_field_name=field_name)
if isinstance(exception, exceptions.NotAuthorized):
logout_reason = _("Unauthorized. Please try logging in again.")
utils.add_logout_reason(request, response, logout_reason)
response.delete_cookie('messages')
if request.is_ajax():
response_401 = http.HttpResponse(status=401)
response_401['X-Horizon-Location'] = response['location']
return response_401
return response
if isinstance(exception, exceptions.NotFound):
raise http.Http404(exception)
if isinstance(exception, exceptions.Http302):
return shortcuts.redirect(exception.location) |
Subsets and Splits