sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'formatFlow'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '22', '75', '84', '245']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'string', 'children': [], 'value': '""'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'shifts'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'nextIsList'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'function_definition', 'children': ['23', '24', '28']}, {'id': '23', 'type': 'function_name', 'children': [], 'value': 'IsNextList'}; {'id': '24', 'type': 'parameters', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '28', 'type': 'block', 'children': ['29', '36', '47', '73']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '44']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': '=='}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'True', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '53']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '<'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '-'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '70']}, {'id': '55', 'type': 'boolean_operator', 'children': ['56', '63'], 'value': 'and'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '62'], 'value': '=='}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'buf'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '69'], 'value': '=='}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'True', 'children': []}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'False', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '83'], 'value': '-'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '93']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '93', 'type': 'block', 'children': ['94', '100', '147', '179', '237', '241']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '103', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '104', 'type': 'block', 'children': ['105', '112', '120', '124', '146']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'lastShift'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'shifts'}; {'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '-'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'augmented_assignment', 'children': ['114', '115'], 'value': '+='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '*'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'lastShift'}, {'id': '119', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lastShift'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '<'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'if_statement', 'children': ['130', '137']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '136'], 'value': 'not'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'string', 'children': [], 'value': '"<>"'}, {'id': '137', 'type': 'block', 'children': ['138', '142']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '141', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'augmented_assignment', 'children': ['144', '145'], 'value': '+='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'continue_statement', 'children': []}, {'id': '147', 'type': 'if_statement', 'children': ['148', '151']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"<"'}, {'id': '151', 'type': 'block', 'children': ['152', '170', '174', '178']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '156', '164']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '=='}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'nextIsList'}, {'id': '155', 'type': 'False', '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': 'shifts'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'nextIsList'}, {'id': '169', 'type': 'False', 'children': []}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'augmented_assignment', 'children': ['172', '173'], 'value': '+='}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '178', 'type': 'continue_statement', 'children': []}, {'id': '179', 'type': 'if_statement', 'children': ['180', '183']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '182', 'type': 'string', 'children': [], 'value': '">"'}, {'id': '183', 'type': 'block', 'children': ['184', '191', '195', '201', '205', '209', '213', '236']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'shift'}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'shifts'}, {'id': '189', 'type': 'unary_operator', 'children': ['190'], 'value': '-'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'augmented_assignment', 'children': ['193', '194'], 'value': '+='}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'augmented_assignment', 'children': ['197', '198'], 'value': '+='}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '*'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'shift'}; {'id': '200', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'shift'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'augmented_assignment', 'children': ['207', '208'], 'value': '+='}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'augmented_assignment', 'children': ['211', '212'], 'value': '+='}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '213', 'type': 'if_statement', 'children': ['214', '220', '225']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'IsNextList'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'maxIndex'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'nextIsList'}; {'id': '224', 'type': 'True', 'children': []}, {'id': '225', 'type': 'else_clause', 'children': ['226']}; {'id': '226', 'type': 'block', 'children': ['227', '232']}, {'id': '227', 'type': 'delete_statement', 'children': ['228']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'shifts'}; {'id': '230', 'type': 'unary_operator', 'children': ['231'], 'value': '-'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'nextIsList'}, {'id': '235', 'type': 'False', 'children': []}; {'id': '236', 'type': 'continue_statement', 'children': []}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'augmented_assignment', 'children': ['239', '240'], 'value': '+='}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'augmented_assignment', 'children': ['243', '244'], 'value': '+='}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '245', 'type': 'return_statement', 'children': ['246']} | def formatFlow(s):
result = ""
shifts = []
pos = 0
nextIsList = False
def IsNextList(index, maxIndex, buf):
if index == maxIndex:
return False
if buf[index + 1] == '<':
return True
if index < maxIndex - 1:
if buf[index + 1] == '\n' and buf[index + 2] == '<':
return True
return False
maxIndex = len(s) - 1
for index in range(len(s)):
sym = s[index]
if sym == "\n":
lastShift = shifts[-1]
result += sym + lastShift * " "
pos = lastShift
if index < maxIndex:
if s[index + 1] not in "<>":
result += " "
pos += 1
continue
if sym == "<":
if nextIsList == False:
shifts.append(pos)
else:
nextIsList = False
pos += 1
result += sym
continue
if sym == ">":
shift = shifts[-1]
result += '\n'
result += shift * " "
pos = shift
result += sym
pos += 1
if IsNextList(index, maxIndex, s):
nextIsList = True
else:
del shifts[-1]
nextIsList = False
continue
result += sym
pos += 1
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'train'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'training_set'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '500'}, {'id': '9', 'type': 'block', 'children': ['10', '177', '189', '201', '210', '221', '232', '236', '311', '320']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17', '99']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '>'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'training_set'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '17', 'type': 'block', 'children': ['18', '35']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '__X'}, {'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': 'matrix'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'list_comprehension', 'children': ['29', '32']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'example'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'example'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41', '67']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '=='}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '__num_labels'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__y'}, {'id': '47', 'type': 'call', 'children': ['48', '62']}; {'id': '48', 'type': 'attribute', 'children': ['49', '61']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'matrix'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'example'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'example'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'tuple', 'children': ['64', '66']}; {'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '-'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69', '80']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'eye'}; {'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': 'eye'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '__num_labels'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '__y'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'matrix'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '96']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'eye'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'example'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'example'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '99', 'type': 'else_clause', 'children': ['100']}; {'id': '100', 'type': 'block', 'children': ['101', '114']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'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': 'np'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '120', '142']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '119'], 'value': '=='}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '__num_labels'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '__y'}; {'id': '126', 'type': 'call', 'children': ['127', '137']}, {'id': '127', 'type': 'attribute', 'children': ['128', '136']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'tuple', 'children': ['139', '141']}, {'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '142', 'type': 'else_clause', 'children': ['143']}, {'id': '143', 'type': 'block', 'children': ['144', '155']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'eye'}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'eye'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '__num_labels'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': '__y'}; {'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': 'matrix'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'list_comprehension', 'children': ['166', '169', '174']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'eye'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'sublist'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'training_set'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sublist'}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '__m'}; {'id': '182', 'type': 'subscript', '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': '__X'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': '__input_layer_size'}; {'id': '194', 'type': 'subscript', 'children': ['195', '200']}, {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '__X'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '206', 'type': 'list', 'children': ['207'], 'value': '[self.__input_layer_size]'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': '__input_layer_size'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '217']}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '__hidden_layers'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '228']}, {'id': '223', 'type': 'attribute', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '__sizes'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': '__num_labels'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'initial_theta'}, {'id': '235', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '236', 'type': 'for_statement', 'children': ['237', '238', '249']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '248'], 'value': '-'}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '248', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '249', 'type': 'block', 'children': ['250', '278']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '260'], 'value': '/'}; {'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': 'sqrt'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'binary_operator', 'children': ['266', '271'], 'value': '+'}; {'id': '266', 'type': 'subscript', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '271', 'type': 'subscript', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': '__sizes'}, {'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '+'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'call', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'initial_theta'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '310'], 'value': '-'}, {'id': '285', 'type': 'binary_operator', 'children': ['286', '309'], 'value': '*'}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '308'], 'value': '*'}, {'id': '287', 'type': 'call', 'children': ['288', '293']}; {'id': '288', 'type': 'attribute', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'rand'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '301']}; {'id': '294', 'type': 'subscript', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '+'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '307'], 'value': '+'}; {'id': '302', 'type': 'subscript', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': '__sizes'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '308', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'initial_theta'}; {'id': '314', 'type': 'call', 'children': ['315', '318']}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': '__unroll'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'initial_theta'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': '__thetas'}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': '__roll'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'fmin_bfgs'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '336', '337', '342']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': '__cost_function'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'initial_theta'}, {'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'fprime'}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': '__cost_grad_function'}; {'id': '342', 'type': 'keyword_argument', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'maxiter'} | def train(self, training_set, iterations=500):
if len(training_set) > 2:
self.__X = np.matrix([example[0] for example in training_set])
if self.__num_labels == 1:
self.__y = np.matrix([example[1] for example in training_set]).reshape((-1, 1))
else:
eye = np.eye(self.__num_labels)
self.__y = np.matrix([eye[example[1]] for example in training_set])
else:
self.__X = np.matrix(training_set[0])
if self.__num_labels == 1:
self.__y = np.matrix(training_set[1]).reshape((-1, 1))
else:
eye = np.eye(self.__num_labels)
self.__y = np.matrix([eye[index] for sublist in training_set[1] for index in sublist])
self.__m = self.__X.shape[0]
self.__input_layer_size = self.__X.shape[1]
self.__sizes = [self.__input_layer_size]
self.__sizes.extend(self.__hidden_layers)
self.__sizes.append(self.__num_labels)
initial_theta = []
for count in range(len(self.__sizes) - 1):
epsilon = np.sqrt(6) / np.sqrt(self.__sizes[count]+self.__sizes[count+1])
initial_theta.append(np.random.rand(self.__sizes[count+1],self.__sizes[count]+1)*2*epsilon-epsilon)
initial_theta = self.__unroll(initial_theta)
self.__thetas = self.__roll(fmin_bfgs(self.__cost_function, initial_theta, fprime=self.__cost_grad_function, maxiter=iterations)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__cost'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'phase'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '43', '48', '53', '133', '168', '220', '268', '275', '279', '283', '437', '449']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '__roll'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'concatenate'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '40']}; {'id': '26', 'type': 'tuple', 'children': ['27', '39']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ones'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'tuple', 'children': ['33', '38']}, {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[a]'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'calculated_z'}, {'id': '51', 'type': 'list', 'children': ['52'], 'value': '[0]'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '57', '61']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'theta'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '61', 'type': 'block', 'children': ['62', '75', '82', '91', '126']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'z'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '70'], 'value': '*'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}; {'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'theta'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'transpose'}; {'id': '74', 'type': 'argument_list', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'calculated_z'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'a'}, {'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': 'sigmoid'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'z'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '100']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '!='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '99'], 'value': '-'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '123']}, {'id': '109', 'type': 'tuple', 'children': ['110', '122']}; {'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': 'ones'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'tuple', 'children': ['116', '121']}; {'id': '116', 'type': 'subscript', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'calculated_a'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'phase'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '137', 'type': 'block', 'children': ['138', '158']}; {'id': '138', 'type': 'if_statement', 'children': ['139', '144']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': '>'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '__num_labels'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'return_statement', 'children': ['146']}; {'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': 'argmax'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '155']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}, {'id': '153', 'type': 'unary_operator', 'children': ['154'], 'value': '-'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'round'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}; {'id': '166', 'type': 'unary_operator', 'children': ['167'], 'value': '-'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'J'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '217'], 'value': '/'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '196'], 'value': '-'}; {'id': '178', 'type': 'unary_operator', 'children': ['179'], 'value': '-'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'multiply'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '__y'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}; {'id': '194', 'type': 'unary_operator', 'children': ['195'], 'value': '-'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'multiply'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '206']}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '-'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': '__y'}; {'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': 'log'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '-'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}, {'id': '215', 'type': 'unary_operator', 'children': ['216'], 'value': '-'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '__m'}; {'id': '220', 'type': 'if_statement', 'children': ['221', '226']}, {'id': '221', 'type': 'comparison_operator', 'children': ['222', '225'], 'value': '!='}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': '__lambda'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'augmented_assignment', 'children': ['229', '230'], 'value': '+='}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'J'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '262'], 'value': '/'}, {'id': '231', 'type': 'binary_operator', 'children': ['232', '259'], 'value': '*'}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'list_comprehension', 'children': ['238', '256']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'power'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '255']}; {'id': '248', 'type': 'subscript', 'children': ['249', '250', '252']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '250', 'type': 'slice', 'children': ['251']}, {'id': '251', 'type': 'colon', 'children': []}; {'id': '252', 'type': 'slice', 'children': ['253', '254']}, {'id': '253', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '254', 'type': 'colon', 'children': []}, {'id': '255', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '256', 'type': 'for_in_clause', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': '__lambda'}; {'id': '262', 'type': 'parenthesized_expression', 'children': ['263']}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '*'}; {'id': '264', 'type': 'float', 'children': [], 'value': '2.0'}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': '__m'}; {'id': '268', 'type': 'if_statement', 'children': ['269', '272']}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': '=='}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'phase'}, {'id': '271', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'return_statement', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'J'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'reversed_d'}; {'id': '278', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'reversed_theta_grad'}; {'id': '282', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '283', 'type': 'for_statement', 'children': ['284', '285', '292']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '292', 'type': 'block', 'children': ['293', '345', '352', '374', '430']}, {'id': '293', 'type': 'if_statement', 'children': ['294', '297', '309']}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': '=='}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '297', 'type': 'block', 'children': ['298']}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'assignment', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '306'], 'value': '-'}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}; {'id': '304', 'type': 'unary_operator', 'children': ['305'], 'value': '-'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': '__y'}, {'id': '309', 'type': 'else_clause', 'children': ['310']}; {'id': '310', 'type': 'block', 'children': ['311']}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '314', 'type': 'call', 'children': ['315', '318']}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'multiply'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '334']}, {'id': '319', 'type': 'binary_operator', 'children': ['320', '324'], 'value': '*'}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'reversed_d'}; {'id': '322', 'type': 'unary_operator', 'children': ['323'], 'value': '-'}, {'id': '323', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '324', 'type': 'subscript', 'children': ['325', '329', '331']}, {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '327', 'type': 'unary_operator', 'children': ['328'], 'value': '-'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '329', 'type': 'slice', 'children': ['330']}; {'id': '330', 'type': 'colon', 'children': []}, {'id': '331', 'type': 'slice', 'children': ['332', '333']}; {'id': '332', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '333', 'type': 'colon', 'children': []}; {'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': 'sigmoid_grad'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'calculated_z'}, {'id': '341', 'type': 'binary_operator', 'children': ['342', '344'], 'value': '-'}; {'id': '342', 'type': 'unary_operator', 'children': ['343'], 'value': '-'}, {'id': '343', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'reversed_d'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'theta_grad'}, {'id': '355', 'type': 'binary_operator', 'children': ['356', '371'], 'value': '/'}; {'id': '356', 'type': 'binary_operator', 'children': ['357', '365'], 'value': '*'}, {'id': '357', 'type': 'call', 'children': ['358', '364']}; {'id': '358', 'type': 'attribute', 'children': ['359', '363']}, {'id': '359', 'type': 'subscript', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'reversed_d'}, {'id': '361', 'type': 'unary_operator', 'children': ['362'], 'value': '-'}; {'id': '362', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'transpose'}; {'id': '364', 'type': 'argument_list', 'children': []}, {'id': '365', 'type': 'subscript', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'calculated_a'}, {'id': '367', 'type': 'binary_operator', 'children': ['368', '370'], 'value': '-'}; {'id': '368', 'type': 'unary_operator', 'children': ['369'], 'value': '-'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '370', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': '__m'}; {'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': 'self'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': '__lambda'}, {'id': '379', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '380', 'type': 'block', 'children': ['381']}, {'id': '381', 'type': 'expression_statement', 'children': ['382']}; {'id': '382', 'type': 'augmented_assignment', 'children': ['383', '384'], 'value': '+='}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'theta_grad'}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '427'], 'value': '/'}, {'id': '385', 'type': 'binary_operator', 'children': ['386', '424'], 'value': '*'}; {'id': '386', 'type': 'call', 'children': ['387', '390']}, {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '390', 'type': 'argument_list', 'children': ['391', '421']}, {'id': '391', 'type': 'tuple', 'children': ['392', '409']}; {'id': '392', 'type': 'call', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'tuple', 'children': ['398', '408']}; {'id': '398', 'type': 'subscript', 'children': ['399', '407']}, {'id': '399', 'type': 'attribute', 'children': ['400', '406']}; {'id': '400', 'type': 'subscript', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '402', 'type': 'binary_operator', 'children': ['403', '405'], 'value': '-'}, {'id': '403', 'type': 'unary_operator', 'children': ['404'], 'value': '-'}; {'id': '404', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '407', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '408', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '409', 'type': 'subscript', 'children': ['410', '416', '418']}; {'id': '410', 'type': 'subscript', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '412', 'type': 'binary_operator', 'children': ['413', '415'], 'value': '-'}, {'id': '413', 'type': 'unary_operator', 'children': ['414'], 'value': '-'}; {'id': '414', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '416', 'type': 'slice', 'children': ['417']}, {'id': '417', 'type': 'colon', 'children': []}; {'id': '418', 'type': 'slice', 'children': ['419', '420']}, {'id': '419', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '420', 'type': 'colon', 'children': []}, {'id': '421', 'type': 'keyword_argument', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '423', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': '__lambda'}, {'id': '427', 'type': 'attribute', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': '__m'}; {'id': '430', 'type': 'expression_statement', 'children': ['431']}, {'id': '431', 'type': 'call', 'children': ['432', '435']}; {'id': '432', 'type': 'attribute', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'reversed_theta_grad'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '435', 'type': 'argument_list', 'children': ['436']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'theta_grad'}, {'id': '437', 'type': 'expression_statement', 'children': ['438']}; {'id': '438', 'type': 'assignment', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'theta_grad'}; {'id': '440', 'type': 'call', 'children': ['441', '444']}, {'id': '441', 'type': 'attribute', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': '__unroll'}; {'id': '444', 'type': 'argument_list', 'children': ['445']}, {'id': '445', 'type': 'call', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '447', 'type': 'argument_list', 'children': ['448']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'reversed_theta_grad'}, {'id': '449', 'type': 'return_statement', 'children': ['450']} | def __cost(self, params, phase, X):
params = self.__roll(params)
a = np.concatenate((np.ones((X.shape[0], 1)), X), axis=1)
calculated_a = [a]
calculated_z = [0]
for i, theta in enumerate(params):
z = calculated_a[-1] * theta.transpose()
calculated_z.append(z)
a = self.sigmoid(z)
if i != len(params) - 1:
a = np.concatenate((np.ones((a.shape[0], 1)), a), axis=1)
calculated_a.append(a)
if phase == 0:
if self.__num_labels > 1:
return np.argmax(calculated_a[-1], axis=1)
return np.round(calculated_a[-1])
J = np.sum(-np.multiply(self.__y, np.log(calculated_a[-1]))-np.multiply(1-self.__y, np.log(1-calculated_a[-1])))/self.__m;
if self.__lambda != 0:
J += np.sum([np.sum(np.power(theta[:,1:], 2)) for theta in params])*self.__lambda/(2.0*self.__m)
if phase == 1:
return J
reversed_d = []
reversed_theta_grad = []
for i in range(len(params)):
if i == 0:
d = calculated_a[-1] - self.__y
else:
d = np.multiply(reversed_d[-1]*params[-i][:,1:], self.sigmoid_grad(calculated_z[-1-i]))
reversed_d.append(d)
theta_grad = reversed_d[-1].transpose() * calculated_a[-i-2] / self.__m
if self.__lambda != 0:
theta_grad += np.concatenate((np.zeros((params[-1-i].shape[0], 1)), params[-1-i][:,1:]), axis=1) * self.__lambda / self.__m
reversed_theta_grad.append(theta_grad)
theta_grad = self.__unroll(reversed(reversed_theta_grad))
return theta_grad |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_many'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '19', '26', '141', '180']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'unique_indexes'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_uniqueIndexes'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'NO_SUCH_ATTR'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'object'}; {'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': 'new_objs'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'unique_indexes'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'unique_indexes'}; {'id': '32', 'type': 'block', 'children': ['33', '39', '56', '92', '110']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'new_keys'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '44', 'type': 'generator_expression', 'children': ['45', '53']}, {'id': '45', 'type': 'tuple', 'children': ['46', '52']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'NO_SUCH_ATTR'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'new_objs'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '70']}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '62'], 'value': 'and'}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'accept_none'}; {'id': '62', 'type': 'parenthesized_expression', 'children': ['63']}, {'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'or'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'in'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'new_keys'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'NO_SUCH_ATTR'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'new_keys'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'raise_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '78']}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '%'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"unique key cannot be None or blank for index %s"'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '80', '83']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'new_objs'}, {'id': '83', 'type': 'if_clause', 'children': ['84']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '91'], 'value': 'is'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89', '90']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ob'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'NO_SUCH_ATTR'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'if_statement', 'children': ['93', '102']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '98'], 'value': '<'}; {'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': 'new_keys'}; {'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': 'new_objs'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'raise_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '%'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"given sequence contains duplicate keys for index %s"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_keys'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'in'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '118', 'type': 'block', 'children': ['119', '125']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'new_keys'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '125', 'type': 'raise_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '138']}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"duplicate unique key value \'%s\' for index %s"'}, {'id': '131', 'type': 'tuple', 'children': ['132', '137']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ind_attr'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'new_keys'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'new_objs'}; {'id': '144', 'type': 'block', 'children': ['145', '154']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '158', '165']}, {'id': '155', 'type': 'pattern_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '158', 'type': 'call', 'children': ['159', '164']}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_indexes'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'block', 'children': ['166', '174']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'obval'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'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': 'ind'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'obval'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'} | def insert_many(self, it):
unique_indexes = self._uniqueIndexes
NO_SUCH_ATTR = object()
new_objs = list(it)
if unique_indexes:
for ind in unique_indexes:
ind_attr = ind.attr
new_keys = dict((getattr(obj, ind_attr, NO_SUCH_ATTR), obj) for obj in new_objs)
if not ind.accept_none and (None in new_keys or NO_SUCH_ATTR in new_keys):
raise KeyError("unique key cannot be None or blank for index %s" % ind_attr,
[ob for ob in new_objs if getattr(ob, ind_attr, NO_SUCH_ATTR) is None])
if len(new_keys) < len(new_objs):
raise KeyError("given sequence contains duplicate keys for index %s" % ind_attr)
for key in new_keys:
if key in ind:
obj = new_keys[key]
raise KeyError("duplicate unique key value '%s' for index %s" % (getattr(obj, ind_attr), ind_attr),
new_keys[key])
for obj in new_objs:
self.obs.append(obj)
for attr, ind in self._indexes.items():
obval = getattr(obj, attr)
ind[obval] = obj
return self |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_query_attr_sort_fn'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr_val'}; {'id': '6', 'type': 'block', 'children': ['7', '13']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'attr_val'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19', '44']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_indexes'}, {'id': '19', 'type': 'block', 'children': ['20', '28']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_indexes'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32', '40']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'else_clause', 'children': ['45']}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'float', 'children': [], 'value': '1e9'} | def _query_attr_sort_fn(self, attr_val):
attr, v = attr_val
if attr in self._indexes:
idx = self._indexes[attr]
if v in idx:
return len(idx[v])
else:
return 0
else:
return 1e9 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '227']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19', '207']}, {'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': 'key'}, {'id': '15', 'type': 'tuple', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '19', 'type': 'block', 'children': ['20', '101', '111']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26', '64']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '26', 'type': 'block', 'children': ['27', '44']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'attrdefs'}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "','"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}, {'id': '47', 'type': 'list_comprehension', 'children': ['48', '61']}; {'id': '48', 'type': 'subscript', 'children': ['49', '58']}, {'id': '49', 'type': 'parenthesized_expression', 'children': ['50']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '56'], 'value': '+'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'list', 'children': ['57'], 'value': "['asc', ]"}, {'id': '57', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '58', 'type': 'slice', 'children': ['59', '60']}, {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'attrdefs'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '74', '95']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '92']}, {'id': '79', 'type': 'subscript', 'children': ['80', '89']}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '87'], 'value': '+'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'list', 'children': ['88'], 'value': "['asc', ]"}; {'id': '88', 'type': 'string', 'children': [], 'value': "'asc'"}, {'id': '89', 'type': 'slice', 'children': ['90', '91']}; {'id': '90', 'type': 'colon', 'children': []}, {'id': '91', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'else_clause', 'children': ['96']}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '110']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '123', '142', '174']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '114', 'type': 'generator_expression', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '118', 'type': 'for_in_clause', 'children': ['119', '122']}, {'id': '119', 'type': 'pattern_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '139']}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'attrgetter'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'list_splat', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '142', 'type': 'elif_clause', 'children': ['143', '154']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '145', 'type': 'generator_expression', 'children': ['146', '149']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'desc'"}, {'id': '149', 'type': 'for_in_clause', 'children': ['150', '153']}; {'id': '150', 'type': 'pattern_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '162']}, {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '170']}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'attrgetter'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'list_splat', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '172', 'type': 'not_operator', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '174', 'type': 'else_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'do_all'}, {'id': '179', 'type': 'generator_expression', 'children': ['180', '199']}; {'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': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '193']}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'attrgetter'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '195', 'type': 'parenthesized_expression', 'children': ['196']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"desc"'}, {'id': '199', 'type': 'for_in_clause', 'children': ['200', '203']}; {'id': '200', 'type': 'pattern_list', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'attr_orders'}, {'id': '207', 'type': 'else_clause', 'children': ['208']}; {'id': '208', 'type': 'block', 'children': ['209', '213']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'keyfn'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '220']}, {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '224']}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'keyfn'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '227', 'type': 'return_statement', 'children': ['228']} | def sort(self, key, reverse=False):
if isinstance(key, (basestring, list, tuple)):
if isinstance(key, basestring):
attrdefs = [s.strip() for s in key.split(',')]
attr_orders = [(a.split()+['asc', ])[:2] for a in attrdefs]
else:
if isinstance(key[0], basestring):
attr_orders = [(a.split()+['asc', ])[:2] for a in key]
else:
attr_orders = key
attrs = [attr for attr, order in attr_orders]
if all(order == 'asc' for attr, order in attr_orders):
self.obs.sort(key=attrgetter(*attrs), reverse=reverse)
elif all(order == 'desc' for attr, order in attr_orders):
self.obs.sort(key=attrgetter(*attrs), reverse=not reverse)
else:
do_all(self.obs.sort(key=attrgetter(attr), reverse=(order == "desc"))
for attr, order in reversed(attr_orders))
else:
keyfn = key
self.obs.sort(key=keyfn, reverse=reverse)
return self |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '41', '62', '66', '114', '130', '136', '169']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_parse_fields_string'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '18', 'type': 'function_definition', 'children': ['19', '20', '22']}, {'id': '19', 'type': 'function_name', 'children': [], 'value': '_make_string_callable'}; {'id': '20', 'type': 'parameters', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '29', '37']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'lambda', 'children': ['32', '34']}; {'id': '32', 'type': 'lambda_parameters', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '%'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '46', 'type': 'generator_expression', 'children': ['47', '53']}, {'id': '47', 'type': 'tuple', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_make_string_callable'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '53', 'type': 'for_in_clause', 'children': ['54', '57']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'raw_tuples'}, {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '71']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '71', 'type': 'block', 'children': ['72', '87', '107']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'attrvalues'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '77', 'type': 'generator_expression', 'children': ['78', '84']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fieldname'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'fieldname'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'exprs'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'augmented_assignment', 'children': ['92', '93'], 'value': '+='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'attrvalues'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '95', 'type': 'generator_expression', 'children': ['96', '100']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'exprs'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '106', 'type': 'argument_list', 'children': []}, {'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': 'raw_tuples'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'attrvalues'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'all_names'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '122'], 'value': '+'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'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': 'ret'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'Table'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'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': 'ret'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_indexes'}; {'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': 'dict'}; {'id': '146', 'type': 'generator_expression', 'children': ['147', '154', '165']}, {'id': '147', 'type': 'tuple', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'copy_template'}, {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'for_in_clause', 'children': ['155', '158']}, {'id': '155', 'type': 'pattern_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '158', 'type': 'call', 'children': ['159', '164']}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_indexes'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'if_clause', 'children': ['166']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'in'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'all_names'}, {'id': '169', 'type': 'return_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'id': '171', 'type': 'attribute', 'children': ['172', '175']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'insert_many'}; {'id': '176', 'type': 'generator_expression', 'children': ['177', '189']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'dictionary_splat', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'all_names'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'outtuple'}, {'id': '189', 'type': 'for_in_clause', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'outtuple'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'raw_tuples'} | def select(self, fields, **exprs):
fields = self._parse_fields_string(fields)
def _make_string_callable(expr):
if isinstance(expr, basestring):
return lambda r: expr % r
else:
return expr
exprs = dict((k, _make_string_callable(v)) for k, v in exprs.items())
raw_tuples = []
for ob in self.obs:
attrvalues = tuple(getattr(ob, fieldname, None) for fieldname in fields)
if exprs:
attrvalues += tuple(expr(ob) for expr in exprs.values())
raw_tuples.append(attrvalues)
all_names = tuple(fields) + tuple(exprs.keys())
ret = Table()
ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items() if k in all_names))
return ret().insert_many(DataObject(**dict(zip(all_names, outtuple))) for outtuple in raw_tuples) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_import'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'csv_source'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'transforms'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'row_class'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '17', 'type': 'block', 'children': ['18', '44', '58']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'reader_args'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '23', 'type': 'generator_expression', 'children': ['24', '27', '36']}; {'id': '24', 'type': 'tuple', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '31']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'if_clause', 'children': ['37']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '39', 'type': 'list', 'children': ['40', '41', '42', '43'], 'value': "['encoding',\n 'csv_source',\n 'transforms',\n 'row_class']"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'encoding'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'csv_source'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'transforms'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'row_class'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '47', 'type': 'lambda', 'children': ['48', '50']}; {'id': '48', 'type': 'lambda_parameters', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'csv'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'DictReader'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '56', 'type': 'dictionary_splat', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'reader_args'}; {'id': '58', 'type': 'return_statement', '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': '_import'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66', '67', '70']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'csv_source'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'transforms'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'row_class'} | def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs):
reader_args = dict((k, v) for k, v in kwargs.items() if k not in ['encoding',
'csv_source',
'transforms',
'row_class'])
reader = lambda src: csv.DictReader(src, **reader_args)
return self._import(csv_source, encoding, transforms, reader=reader, row_class=row_class) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_export'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"UTF-8"'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '55']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '23', 'type': 'block', 'children': ['24', '51']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26', '41']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PY_3'}; {'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': 'csv_dest'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '38']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '37', 'type': 'string', 'children': [], 'value': "''"}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'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': 'csv_dest'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'wb'"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}; {'id': '54', 'type': 'True', 'children': []}, {'id': '55', 'type': 'try_statement', 'children': ['56', '187']}; {'id': '56', 'type': 'block', 'children': ['57', '76', '91', '105', '121']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_object_attrnames'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '82']}, {'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': 'fieldnames'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'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': 'fieldnames'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '104'], 'value': '+'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "','"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'NL'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'csvout'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'csv'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'DictWriter'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115', '118']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'csv_dest'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}, {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'extrasaction'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'lineterminator'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'NL'}, {'id': '121', 'type': 'if_statement', 'children': ['122', '131', '146']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '130']}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"__dict__"'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'csvout'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'writerows'}, {'id': '137', 'type': 'generator_expression', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '146', 'type': 'else_clause', 'children': ['147']}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'do_all'}, {'id': '151', 'type': 'generator_expression', 'children': ['152', '182']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'csvout'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'writerow'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ODict'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'starmap'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '174']}, {'id': '163', 'type': 'lambda', 'children': ['164', '167']}; {'id': '164', 'type': 'lambda_parameters', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fld'}, {'id': '167', 'type': 'tuple', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'fld'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'fld'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '181']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'repeat'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '182', 'type': 'for_in_clause', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '187', 'type': 'finally_clause', 'children': ['188']}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'if_statement', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}, {'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': 'csv_dest'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '197', 'type': 'argument_list', 'children': []} | def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"):
close_on_exit = False
if isinstance(csv_dest, basestring):
if PY_3:
csv_dest = open(csv_dest, 'w', newline='', encoding=encoding)
else:
csv_dest = open(csv_dest, 'wb')
close_on_exit = True
try:
if fieldnames is None:
fieldnames = list(_object_attrnames(self.obs[0]))
if isinstance(fieldnames, basestring):
fieldnames = fieldnames.split()
csv_dest.write(','.join(fieldnames) + NL)
csvout = csv.DictWriter(csv_dest, fieldnames, extrasaction='ignore', lineterminator=NL)
if hasattr(self.obs[0], "__dict__"):
csvout.writerows(o.__dict__ for o in self.obs)
else:
do_all(csvout.writerow(ODict(starmap(lambda obj, fld: (fld, getattr(obj, fld)),
zip(repeat(o), fieldnames)))) for o in self.obs)
finally:
if close_on_exit:
csv_dest.close() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_import'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"UTF-8"'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'transforms'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'row_class'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '15', 'type': 'block', 'children': ['16', '77']}; {'id': '16', 'type': 'class_definition', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_JsonFileReader'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '20', 'type': 'block', 'children': ['21', '33']}, {'id': '21', 'type': 'function_definition', 'children': ['22', '23', '26']}; {'id': '22', 'type': 'function_name', 'children': [], 'value': '__init__'}, {'id': '23', 'type': 'parameters', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'src'}, {'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']}; {'id': '34', 'type': 'function_name', 'children': [], 'value': '__iter__'}, {'id': '35', 'type': 'parameters', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'block', 'children': ['38', '42']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'current'}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '47']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '47', 'type': 'block', 'children': ['48', '55', '59']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '54', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '59', 'type': 'try_statement', 'children': ['60', '73']}; {'id': '60', 'type': 'block', 'children': ['61', '69']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'yield', 'children': ['63']}, {'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': 'loads'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'current'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '72', 'type': 'string', 'children': [], 'value': "''"}, {'id': '73', 'type': 'except_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'pass_statement', 'children': []}, {'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': '_import'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85', '88', '91']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'transforms'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'transforms'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_JsonFileReader'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'row_class'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'row_class'} | def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject):
class _JsonFileReader(object):
def __init__(self, src):
self.source = src
def __iter__(self):
current = ''
for line in self.source:
if current:
current += ' '
current += line
try:
yield json.loads(current)
current = ''
except Exception:
pass
return self._import(source, encoding, transforms=transforms, reader=_JsonFileReader, row_class=row_class) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_export'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"UTF-8"'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '52']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '23', 'type': 'block', 'children': ['24', '48']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26', '38']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PY_3'}; {'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': 'dest'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dest'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'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', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'try_statement', 'children': ['53', '130']}, {'id': '53', 'type': 'block', 'children': ['54', '69']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '60']}, {'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': 'fieldnames'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73', '94']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '72', 'type': 'None', 'children': []}, {'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': 'do_all'}, {'id': '77', 'type': 'generator_expression', 'children': ['78', '89']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '88'], 'value': '+'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_to_json'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'do_all'}, {'id': '99', 'type': 'generator_expression', 'children': ['100', '125']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '124'], 'value': '+'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ODict'}, {'id': '113', 'type': 'generator_expression', 'children': ['114', '121']}; {'id': '114', 'type': 'tuple', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fieldnames'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '130', 'type': 'finally_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'close_on_exit'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dest'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'close'} | def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
close_on_exit = False
if isinstance(dest, basestring):
if PY_3:
dest = open(dest, 'w', encoding=encoding)
else:
dest = open(dest, 'w')
close_on_exit = True
try:
if isinstance(fieldnames, basestring):
fieldnames = fieldnames.split()
if fieldnames is None:
do_all(dest.write(_to_json(o)+'\n') for o in self.obs)
else:
do_all(dest.write(json.dumps(ODict((f, getattr(o, f)) for f in fieldnames))+'\n') for o in self.obs)
finally:
if close_on_exit:
dest.close() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupby'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'outexprs'}; {'id': '8', 'type': 'block', 'children': ['9', '68', '75', '95', '101', '123', '180']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '15', '41', '61']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '15', 'type': 'block', 'children': ['16', '24']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'keyfn'}, {'id': '27', 'type': 'lambda', 'children': ['28', '30']}; {'id': '28', 'type': 'lambda_parameters', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '32', 'type': 'generator_expression', 'children': ['33', '38']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}, {'id': '41', 'type': 'elif_clause', 'children': ['42', '47']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '47', 'type': 'block', 'children': ['48', '55']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}, {'id': '51', 'type': 'tuple', 'children': ['52']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'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': 'keyfn'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'keyexpr'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'raise_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"keyexpr must be string or tuple"'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'groupedobs'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'do_all'}; {'id': '78', 'type': 'generator_expression', 'children': ['79', '90']}, {'id': '79', 'type': 'call', 'children': ['80', '88']}; {'id': '80', 'type': 'attribute', 'children': ['81', '87']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'groupedobs'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'keyfn'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ob'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ob'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'tbl'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'Table'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'do_all'}; {'id': '104', 'type': 'generator_expression', 'children': ['105', '120']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tbl'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'create_index'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '113', 'type': 'parenthesized_expression', 'children': ['114']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '119'], 'value': '=='}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}, {'id': '123', 'type': 'for_statement', 'children': ['124', '127', '135']}; {'id': '124', 'type': 'pattern_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'recs'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'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': 'groupedobs'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '134', 'type': 'argument_list', 'children': []}, {'id': '135', 'type': 'block', 'children': ['136', '151', '173']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'groupobj'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'dictionary_splat', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'do_all'}; {'id': '154', 'type': 'generator_expression', 'children': ['155', '164']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'groupobj'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'subkey'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'recs'}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '168']}, {'id': '165', 'type': 'pattern_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'subkey'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'outexprs'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '172', 'type': 'argument_list', 'children': []}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'tbl'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'groupobj'}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'tbl'} | def groupby(self, keyexpr, **outexprs):
if isinstance(keyexpr, basestring):
keyattrs = keyexpr.split()
keyfn = lambda o: tuple(getattr(o, k) for k in keyattrs)
elif isinstance(keyexpr, tuple):
keyattrs = (keyexpr[0],)
keyfn = keyexpr[1]
else:
raise TypeError("keyexpr must be string or tuple")
groupedobs = defaultdict(list)
do_all(groupedobs[keyfn(ob)].append(ob) for ob in self.obs)
tbl = Table()
do_all(tbl.create_index(k, unique=(len(keyattrs) == 1)) for k in keyattrs)
for key, recs in sorted(groupedobs.items()):
groupobj = DataObject(**dict(zip(keyattrs, key)))
do_all(setattr(groupobj, subkey, expr(recs)) for subkey, expr in outexprs.items())
tbl.insert(groupobj)
return tbl |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_counts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'count_fn'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'colwidth'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '26', '143', '456']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '25'], 'value': '=='}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'block', 'children': ['27', '43', '63', '67', '71', '108']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"Pivot: %s\\n"'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "','"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '48', 'type': 'generator_expression', 'children': ['49', '56']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'colwidth'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'keytally'}; {'id': '70', 'type': 'dictionary', 'children': []}, {'id': '71', 'type': 'for_statement', 'children': ['72', '75', '80']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'block', 'children': ['81', '88', '102']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sub_v'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'count_fn'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sub_v'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'keytally'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sub_v'}; {'id': '108', 'type': 'for_statement', 'children': ['109', '112', '117']}, {'id': '109', 'type': 'pattern_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'block', 'children': ['118', '130']}; {'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': 'out'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '%'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"%-*.*s "'}; {'id': '126', 'type': 'tuple', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'k'}; {'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': 'out'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '%'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"%*s\\n"'}; {'id': '138', 'type': 'tuple', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'keytally'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '143', 'type': 'elif_clause', 'children': ['144', '152']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '151'], 'value': '=='}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '152', 'type': 'block', 'children': ['153', '169', '193', '221', '241', '252', '280', '291', '393', '405', '433']}, {'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': 'out'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': '"Pivot: %s\\n"'}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': "','"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '192']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '177', 'type': 'generator_expression', 'children': ['178', '185']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '185', 'type': 'for_in_clause', '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': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '220']}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '201', 'type': 'generator_expression', 'children': ['202', '209']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '211', 'type': 'call', 'children': ['212', '219']}; {'id': '212', 'type': 'attribute', 'children': ['213', '218']}, {'id': '213', 'type': 'subscript', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '217', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'colwidth'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'keytally'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '226', 'type': 'generator_expression', 'children': ['227', '230']}, {'id': '227', 'type': 'tuple', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '232', 'type': 'call', 'children': ['233', '240']}, {'id': '233', 'type': 'attribute', 'children': ['234', '239']}; {'id': '234', 'type': 'subscript', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'subtables'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '240', 'type': 'argument_list', 'children': []}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'}; {'id': '248', 'type': 'string', 'children': [], 'value': '"%*s "'}, {'id': '249', 'type': 'tuple', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}, {'id': '251', 'type': 'string', 'children': [], 'value': "''"}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '262', 'type': 'generator_expression', 'children': ['263', '269']}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '%'}; {'id': '264', 'type': 'string', 'children': [], 'value': '"%*.*s"'}, {'id': '265', 'type': 'tuple', 'children': ['266', '267', '268']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '269', 'type': 'for_in_clause', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '271', 'type': 'call', 'children': ['272', '279']}; {'id': '272', 'type': 'attribute', 'children': ['273', '278']}, {'id': '273', 'type': 'subscript', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '279', 'type': 'argument_list', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'}, {'id': '287', 'type': 'string', 'children': [], 'value': "' %*s\\n'"}; {'id': '288', 'type': 'tuple', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'Total'"}, {'id': '291', 'type': 'for_statement', 'children': ['292', '295', '300']}; {'id': '292', 'type': 'pattern_list', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '299', 'type': 'argument_list', 'children': []}; {'id': '300', 'type': 'block', 'children': ['301', '313', '361', '368', '382']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '%'}; {'id': '308', 'type': 'string', 'children': [], 'value': '"%-*.*s "'}, {'id': '309', 'type': 'tuple', 'children': ['310', '311', '312']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '313', 'type': 'for_statement', 'children': ['314', '317', '322']}; {'id': '314', 'type': 'pattern_list', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'kk'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'ssub'}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '321', 'type': 'argument_list', 'children': []}; {'id': '322', 'type': 'block', 'children': ['323', '330', '341', '347']}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'ssub_v'}; {'id': '326', 'type': 'call', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'count_fn'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'ssub'}; {'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': 'out'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '%'}, {'id': '337', 'type': 'string', 'children': [], 'value': '"%*d "'}; {'id': '338', 'type': 'tuple', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'ssub_v'}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'augmented_assignment', 'children': ['343', '346'], 'value': '+='}, {'id': '343', 'type': 'subscript', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'keytally'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'kk'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'ssub_v'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '352', 'type': 'argument_list', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '354', 'type': 'call', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'ssub_v'}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'sub_v'}; {'id': '364', 'type': 'call', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'count_fn'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '371', 'type': 'call', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '373', 'type': 'argument_list', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '375', 'type': 'call', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'call', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'sub_v'}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'call', 'children': ['384', '387']}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '387', 'type': 'argument_list', 'children': ['388']}; {'id': '388', 'type': 'binary_operator', 'children': ['389', '390'], 'value': '%'}, {'id': '389', 'type': 'string', 'children': [], 'value': '"%*d\\n"'}; {'id': '390', 'type': 'tuple', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'sub_v'}, {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'call', 'children': ['395', '398']}, {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '398', 'type': 'argument_list', 'children': ['399']}, {'id': '399', 'type': 'binary_operator', 'children': ['400', '401'], 'value': '%'}; {'id': '400', 'type': 'string', 'children': [], 'value': "'%-*.*s '"}, {'id': '401', 'type': 'tuple', 'children': ['402', '403', '404']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'maxkeylen'}; {'id': '404', 'type': 'string', 'children': [], 'value': '"Total"'}, {'id': '405', 'type': 'expression_statement', 'children': ['406']}; {'id': '406', 'type': 'call', 'children': ['407', '410']}, {'id': '407', 'type': 'attribute', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '410', 'type': 'argument_list', 'children': ['411']}, {'id': '411', 'type': 'call', 'children': ['412', '415']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}, {'id': '413', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '415', 'type': 'generator_expression', 'children': ['416', '421']}; {'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '%'}, {'id': '417', 'type': 'string', 'children': [], 'value': '"%*d"'}; {'id': '418', 'type': 'tuple', 'children': ['419', '420']}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'tally'}, {'id': '421', 'type': 'for_in_clause', 'children': ['422', '425']}; {'id': '422', 'type': 'pattern_list', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'tally'}, {'id': '425', 'type': 'call', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '427', 'type': 'argument_list', 'children': ['428']}; {'id': '428', 'type': 'call', 'children': ['429', '432']}, {'id': '429', 'type': 'attribute', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'keytally'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '432', 'type': 'argument_list', 'children': []}, {'id': '433', 'type': 'expression_statement', 'children': ['434']}; {'id': '434', 'type': 'call', 'children': ['435', '438']}, {'id': '435', 'type': 'attribute', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '438', 'type': 'argument_list', 'children': ['439']}, {'id': '439', 'type': 'binary_operator', 'children': ['440', '441'], 'value': '%'}; {'id': '440', 'type': 'string', 'children': [], 'value': '" %*d\\n"'}, {'id': '441', 'type': 'tuple', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'maxvallen'}, {'id': '443', 'type': 'call', 'children': ['444', '445']}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '445', 'type': 'generator_expression', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'tally'}, {'id': '447', 'type': 'for_in_clause', 'children': ['448', '451']}; {'id': '448', 'type': 'pattern_list', 'children': ['449', '450']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'tally'}, {'id': '451', 'type': 'call', 'children': ['452', '455']}; {'id': '452', 'type': 'attribute', 'children': ['453', '454']}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'keytally'}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '455', 'type': 'argument_list', 'children': []}; {'id': '456', 'type': 'else_clause', 'children': ['457']}, {'id': '457', 'type': 'block', 'children': ['458']}; {'id': '458', 'type': 'raise_statement', 'children': ['459']}, {'id': '459', 'type': 'call', 'children': ['460', '461']}; {'id': '460', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '461', 'type': 'argument_list', 'children': ['462']} | def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
if len(self._pivot_attrs) == 1:
out.write("Pivot: %s\n" % ','.join(self._pivot_attrs))
maxkeylen = max(len(str(k)) for k in self.keys())
maxvallen = colwidth
keytally = {}
for k, sub in self.items():
sub_v = count_fn(sub)
maxvallen = max(maxvallen, len(str(sub_v)))
keytally[k] = sub_v
for k, sub in self.items():
out.write("%-*.*s " % (maxkeylen, maxkeylen, k))
out.write("%*s\n" % (maxvallen, keytally[k]))
elif len(self._pivot_attrs) == 2:
out.write("Pivot: %s\n" % ','.join(self._pivot_attrs))
maxkeylen = max(max(len(str(k)) for k in self.keys()), 5)
maxvallen = max(max(len(str(k)) for k in self.subtables[0].keys()), colwidth)
keytally = dict((k, 0) for k in self.subtables[0].keys())
out.write("%*s " % (maxkeylen, ''))
out.write(' '.join("%*.*s" % (maxvallen, maxvallen, k) for k in self.subtables[0].keys()))
out.write(' %*s\n' % (maxvallen, 'Total'))
for k, sub in self.items():
out.write("%-*.*s " % (maxkeylen, maxkeylen, k))
for kk, ssub in sub.items():
ssub_v = count_fn(ssub)
out.write("%*d " % (maxvallen, ssub_v))
keytally[kk] += ssub_v
maxvallen = max(maxvallen, len(str(ssub_v)))
sub_v = count_fn(sub)
maxvallen = max(maxvallen, len(str(sub_v)))
out.write("%*d\n" % (maxvallen, sub_v))
out.write('%-*.*s ' % (maxkeylen, maxkeylen, "Total"))
out.write(' '.join("%*d" % (maxvallen, tally) for k, tally in sorted(keytally.items())))
out.write(" %*d\n" % (maxvallen, sum(tally for k, tally in keytally.items())))
else:
raise ValueError("can only dump summary counts for 1 or 2-attribute pivots") |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_table'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'col_label'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '24', '42', '48', '63', '307']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'col_label'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'col_label'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '33']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'col_label'}; {'id': '36', 'type': 'None', 'children': []}, {'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': 'col_label'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'Table'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'do_all'}, {'id': '51', 'type': 'generator_expression', 'children': ['52', '58']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'create_index'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '72', '142', '218', '300']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '71'], 'value': '=='}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'subtables'}; {'id': '78', 'type': 'block', 'children': ['79', '90', '97', '131']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'subattr'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'subval'}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_attr_path'}; {'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '93', 'type': 'dictionary', 'children': ['94']}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'subattr'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'subval'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '105', '115']}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'or'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'attrdict'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'col_label'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '115', 'type': 'else_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'col_label'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '124', 'type': 'generator_expression', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'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': 'ret'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'dictionary_splat', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'attrdict'}; {'id': '142', 'type': 'elif_clause', 'children': ['143', '151']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '150'], 'value': '=='}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '157']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'for_statement', 'children': ['159', '160', '163']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ssub'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '163', 'type': 'block', 'children': ['164', '173', '207']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ssub'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_attr_path'}, {'id': '173', 'type': 'if_statement', 'children': ['174', '181', '191']}; {'id': '174', 'type': 'boolean_operator', 'children': ['175', '178'], 'value': 'or'}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'is'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '177', 'type': 'None', 'children': []}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '187']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'attrdict'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'col_label'}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ssub'}, {'id': '191', 'type': 'else_clause', 'children': ['192']}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'col_label'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '200', 'type': 'generator_expression', 'children': ['201', '204']}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '204', 'type': 'for_in_clause', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ssub'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'dictionary_splat', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'attrdict'}; {'id': '218', 'type': 'elif_clause', 'children': ['219', '227']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '226'], 'value': '=='}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': '_pivot_attrs'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'for_statement', 'children': ['229', '230', '233']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'for_statement', 'children': ['235', '236', '239']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ssub'}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'for_statement', 'children': ['241', '242', '245']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'sssub'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'ssub'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'subtables'}, {'id': '245', 'type': 'block', 'children': ['246', '255', '289']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'sssub'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': '_attr_path'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '263', '273']}; {'id': '256', 'type': 'boolean_operator', 'children': ['257', '260'], 'value': 'or'}, {'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': 'is'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '259', 'type': 'None', 'children': []}; {'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': 'is'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'len'}, {'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': 'attrdict'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'col_label'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'sssub'}, {'id': '273', 'type': 'else_clause', 'children': ['274']}; {'id': '274', 'type': 'block', 'children': ['275']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '280']}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'attrdict'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'col_label'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '282', 'type': 'generator_expression', 'children': ['283', '286']}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '286', 'type': 'for_in_clause', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sssub'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'DataObject'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'dictionary_splat', 'children': ['299']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'attrdict'}; {'id': '300', 'type': 'else_clause', 'children': ['301']}, {'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': 'ValueError'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'string', 'children': [], 'value': '"can only dump summary counts for 1 or 2-attribute pivots"'}, {'id': '307', 'type': 'return_statement', 'children': ['308']} | def as_table(self, fn=None, col=None, col_label=None):
if col_label is None:
col_label = col
if fn is None:
fn = len
if col_label is None:
col_label = 'count'
ret = Table()
do_all(ret.create_index(attr) for attr in self._pivot_attrs)
if len(self._pivot_attrs) == 1:
for sub in self.subtables:
subattr, subval = sub._attr_path[-1]
attrdict = {subattr: subval}
if col is None or fn is len:
attrdict[col_label] = fn(sub)
else:
attrdict[col_label] = fn(s[col] for s in sub)
ret.insert(DataObject(**attrdict))
elif len(self._pivot_attrs) == 2:
for sub in self.subtables:
for ssub in sub.subtables:
attrdict = dict(ssub._attr_path)
if col is None or fn is len:
attrdict[col_label] = fn(ssub)
else:
attrdict[col_label] = fn(s[col] for s in ssub)
ret.insert(DataObject(**attrdict))
elif len(self._pivot_attrs) == 3:
for sub in self.subtables:
for ssub in sub.subtables:
for sssub in ssub.subtables:
attrdict = dict(sssub._attr_path)
if col is None or fn is len:
attrdict[col_label] = fn(sssub)
else:
attrdict[col_label] = fn(s[col] for s in sssub)
ret.insert(DataObject(**attrdict))
else:
raise ValueError("can only dump summary counts for 1 or 2-attribute pivots")
return ret |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_edge'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '7', 'type': 'block', 'children': ['8', '17', '27', '33', '48', '77']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '14'], 'value': '%'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'Dynamically removing uv=(%r, %r)'"}; {'id': '14', 'type': 'tuple', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '24']}, {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'remove_edge'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '30', 'type': 'tuple', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '46']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'forests'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'has_edge'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'return_statement', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '64']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '63'], 'value': '+'}; {'id': '58', 'type': 'subscript', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '74']}, {'id': '67', 'type': 'attribute', 'children': ['68', '73']}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'remove_edge'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '93']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '92'], 'value': '+'}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'block', 'children': ['94', '107', '122', '135', '150', '169', '176']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Tu'}, {'id': '97', 'type': 'call', 'children': ['98', '105']}; {'id': '98', 'type': 'attribute', 'children': ['99', '104']}, {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'forests'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'subtree'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'u'}, {'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': 'binary_operator', 'children': ['112', '113'], 'value': '%'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'Tu = %r'"}, {'id': '113', 'type': 'tuple', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'Tu'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'Tv'}, {'id': '125', 'type': 'call', 'children': ['126', '133']}; {'id': '126', 'type': 'attribute', 'children': ['127', '132']}, {'id': '127', 'type': 'subscript', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'forests'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'subtree'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '%'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Tv = %r'"}, {'id': '141', 'type': 'tuple', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'Tv'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '160']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '156'], 'value': '>'}; {'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': 'Tu'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'Tv'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}, {'id': '163', 'type': 'pattern_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Tu'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'Tv'}; {'id': '166', 'type': 'expression_list', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'Tv'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'Tu'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'seen_'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '176', 'type': 'for_statement', 'children': ['177', '178', '183']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'Tu'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '182', 'type': 'argument_list', 'children': []}, {'id': '183', 'type': 'block', 'children': ['184', '191']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'seen_'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '191', 'type': 'for_statement', 'children': ['192', '193', '201']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '193', 'type': 'call', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'neighbors'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '201', 'type': 'block', 'children': ['202', '208']}; {'id': '202', 'type': 'if_statement', 'children': ['203', '206']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'in'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'seen_'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'continue_statement', 'children': []}; {'id': '208', 'type': 'if_statement', 'children': ['209', '212', '283']}, {'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'in'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'Tv'}; {'id': '212', 'type': 'block', 'children': ['213', '222', '252', '282']}, {'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': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'* Found replacement xy=(%r, %r)'"}, {'id': '219', 'type': 'tuple', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '233']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '230'], 'value': '=='}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'DummyEulerTourForest'}; {'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': 'self'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '251', 'type': 'argument_list', 'children': []}; {'id': '252', 'type': 'for_statement', 'children': ['253', '254', '261']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258']}, {'id': '257', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '+'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '261', 'type': 'block', 'children': ['262', '270']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '%'}, {'id': '267', 'type': 'string', 'children': [], 'value': "'* Add replacment to F[j=%r]'"}; {'id': '268', 'type': 'tuple', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '279']}; {'id': '272', 'type': 'attribute', 'children': ['273', '278']}, {'id': '273', 'type': 'subscript', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'forests'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'add_edge'}, {'id': '279', 'type': 'argument_list', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '282', 'type': 'return_statement', 'children': []}, {'id': '283', 'type': 'else_clause', 'children': ['284']}; {'id': '284', 'type': 'block', 'children': ['285', '294', '324', '351']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'binary_operator', 'children': ['290', '291'], 'value': '%'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'* Charging xy=(%r, %r)'"}, {'id': '291', 'type': 'tuple', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '305']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '302'], 'value': '=='}; {'id': '296', 'type': 'call', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '+'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '304', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '313']}; {'id': '308', 'type': 'attribute', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'DummyEulerTourForest'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '323']}; {'id': '318', 'type': 'attribute', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '323', 'type': 'argument_list', 'children': []}; {'id': '324', 'type': 'if_statement', 'children': ['325', '336']}, {'id': '325', 'type': 'call', 'children': ['326', '333']}; {'id': '326', 'type': 'attribute', 'children': ['327', '332']}, {'id': '327', 'type': 'subscript', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'forests'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'has_edge'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '348']}, {'id': '339', 'type': 'attribute', 'children': ['340', '347']}; {'id': '340', 'type': 'subscript', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'forests'}; {'id': '344', 'type': 'binary_operator', 'children': ['345', '346'], 'value': '+'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '346', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'assignment', 'children': ['353', '360']}, {'id': '353', 'type': 'subscript', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '357', 'type': 'tuple', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '360', 'type': 'binary_operator', 'children': ['361', '362'], 'value': '+'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'i'} | def remove_edge(self, u, v):
print('Dynamically removing uv=(%r, %r)' % (u, v))
self.graph.remove_edge(u, v)
e = (u, v)
if not self.forests[0].has_edge(u, v):
return
for i in reversed(range(0, self.level[e] + 1)):
self.forests[i].remove_edge(u, v)
for i in reversed(range(0, self.level[e] + 1)):
Tu = self.forests[i].subtree(u)
print('Tu = %r' % (list(Tu.nodes()),))
Tv = self.forests[i].subtree(v)
print('Tv = %r' % (list(Tv.nodes()),))
if len(Tu) > len(Tv):
Tu, Tv = Tv, Tu
seen_ = set([])
for x in Tu.nodes():
seen_.add(x)
for y in self.graph.neighbors(x):
if y in seen_:
continue
if y in Tv:
print('* Found replacement xy=(%r, %r)' % (x, y))
if len(self.forests) == i + 1:
self.forests.append(DummyEulerTourForest(self.graph.nodes()))
for j in range(0, i + 2):
print('* Add replacment to F[j=%r]' % (j,))
self.forests[j].add_edge(x, y)
return
else:
print('* Charging xy=(%r, %r)' % (x, y))
if len(self.forests) == i + 1:
self.forests.append(DummyEulerTourForest(self.graph.nodes()))
if self.forests[i].has_edge(x, y):
self.forests[i + 1].add_edge(x, y)
self.level[(x, y)] = i + 1 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_stats_str'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'newlines'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'exclude_keys'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'use_nan'}; {'id': '30', 'type': 'False', 'children': []}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'align'}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'use_median'}; {'id': '36', 'type': 'False', 'children': []}, {'id': '37', 'type': 'dictionary_splat_pattern', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '39', 'type': 'block', 'children': ['40', '46', '51', '82', '108', '121', '129', '353', '366', '383', '398', '411']}; {'id': '40', 'type': 'import_from_statement', 'children': ['41', '44']}, {'id': '41', 'type': 'dotted_name', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '44', 'type': 'dotted_name', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'repr4'}; {'id': '46', 'type': 'import_statement', 'children': ['47']}, {'id': '47', 'type': 'aliased_import', 'children': ['48', '50']}; {'id': '48', 'type': 'dotted_name', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55', '72']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_stats'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '66', '69']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'use_nan'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'use_nan'}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'use_median'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'use_median'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'for_statement', 'children': ['88', '89', '98']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'not'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'delete_statement', 'children': ['105']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'exclude_keys'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'if_statement', 'children': ['113', '116']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'delete_statement', 'children': ['118']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'stat_dict'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '128', 'type': 'argument_list', 'children': []}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '132', 'type': 'None', 'children': []}, {'id': '133', 'type': 'block', 'children': ['134', '142', '153']}; {'id': '134', 'type': 'assert_statement', 'children': ['135', '141']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'is_int'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'precision must be an integer'"}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'float_fmtstr'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '152'], 'value': '+'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'%.'"}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'f'"}, {'id': '153', 'type': 'for_statement', 'children': ['154', '155', '164']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}; {'id': '164', 'type': 'block', 'children': ['165', '171', '180', '239']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'isfloat'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'is_float'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '180', 'type': 'if_statement', 'children': ['181', '189']}, {'id': '181', 'type': 'boolean_operator', 'children': ['182', '184'], 'value': 'and'}; {'id': '182', 'type': 'not_operator', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'isfloat'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '189', 'type': 'block', 'children': ['190', '201']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'type_list'}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '215']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '209'], 'value': 'and'}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '208'], 'value': '>'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'type_list'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'allsame'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'type_list'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'if_statement', 'children': ['217', '225']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'is_float'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'block', 'children': ['226', '230']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'isfloat'}, {'id': '229', 'type': 'True', 'children': []}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '239', 'type': 'if_statement', 'children': ['240', '241', '316']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'isfloat'}, {'id': '241', 'type': 'block', 'children': ['242', '283', '310']}; {'id': '242', 'type': 'if_statement', 'children': ['243', '250', '275']}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '245', 'type': 'argument_list', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '250', 'type': 'block', 'children': ['251']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '254', 'type': 'call', 'children': ['255', '273']}, {'id': '255', 'type': 'attribute', 'children': ['256', '272']}; {'id': '256', 'type': 'call', 'children': ['257', '269']}, {'id': '257', 'type': 'attribute', 'children': ['258', '268']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'list_comprehension', 'children': ['262', '265']}; {'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '%'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'float_fmtstr'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '265', 'type': 'for_in_clause', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'string', 'children': [], 'value': "'\\''"}, {'id': '271', 'type': 'string', 'children': [], 'value': "''"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'string', 'children': [], 'value': "'u'"}, {'id': '275', 'type': 'else_clause', 'children': ['276']}; {'id': '276', 'type': 'block', 'children': ['277']}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '280', 'type': 'binary_operator', 'children': ['281', '282'], 'value': '%'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'float_fmtstr'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '283', 'type': 'if_statement', 'children': ['284', '291']}; {'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': 'strval'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'0'"}, {'id': '291', 'type': 'block', 'children': ['292', '301']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'strval'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'string', 'children': [], 'value': "'0'"}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'strval'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '315']}; {'id': '312', 'type': 'subscript', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '316', 'type': 'else_clause', 'children': ['317']}, {'id': '317', 'type': 'block', 'children': ['318', '347']}; {'id': '318', 'type': 'if_statement', 'children': ['319', '326', '338']}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'strval'}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'tolist'}, {'id': '337', 'type': 'argument_list', 'children': []}; {'id': '338', 'type': 'else_clause', 'children': ['339']}, {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'strval'}, {'id': '343', 'type': 'call', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '345', 'type': 'argument_list', 'children': ['346']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '352']}, {'id': '349', 'type': 'subscript', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'strval'}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'stat_str'}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'repr4'}; {'id': '358', 'type': 'argument_list', 'children': ['359', '360', '363']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'statstr_dict'}; {'id': '360', 'type': 'keyword_argument', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'strvals'}; {'id': '362', 'type': 'True', 'children': []}, {'id': '363', 'type': 'keyword_argument', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'newlines'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'newlines'}; {'id': '366', 'type': 'if_statement', 'children': ['367', '370']}, {'id': '367', 'type': 'comparison_operator', 'children': ['368', '369'], 'value': 'is'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '369', 'type': 'True', 'children': []}; {'id': '370', 'type': 'block', 'children': ['371']}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '374', 'type': 'call', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'get_varname_from_stack'}; {'id': '378', 'type': 'argument_list', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '382', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '383', 'type': 'if_statement', 'children': ['384', '387']}; {'id': '384', 'type': 'comparison_operator', 'children': ['385', '386'], 'value': 'is'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '386', 'type': 'None', 'children': []}, {'id': '387', 'type': 'block', 'children': ['388']}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'assignment', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'stat_str'}, {'id': '391', 'type': 'binary_operator', 'children': ['392', '397'], 'value': '+'}; {'id': '392', 'type': 'binary_operator', 'children': ['393', '396'], 'value': '+'}, {'id': '393', 'type': 'binary_operator', 'children': ['394', '395'], 'value': '+'}; {'id': '394', 'type': 'string', 'children': [], 'value': "'stats_'"}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '396', 'type': 'string', 'children': [], 'value': "' = '"}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'stat_str'}; {'id': '398', 'type': 'if_statement', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'align'}; {'id': '400', 'type': 'block', 'children': ['401']}, {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'assignment', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'stat_str'}; {'id': '404', 'type': 'call', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'align'}; {'id': '408', 'type': 'argument_list', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'stat_str'}; {'id': '410', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '411', 'type': 'return_statement', 'children': ['412']} | def get_stats_str(list_=None, newlines=False, keys=None, exclude_keys=[], lbl=None,
precision=None, axis=0, stat_dict=None, use_nan=False,
align=False, use_median=False, **kwargs):
from utool.util_str import repr4
import utool as ut
if stat_dict is None:
stat_dict = get_stats(list_, axis=axis, use_nan=use_nan, use_median=use_median)
else:
stat_dict = stat_dict.copy()
if keys is not None:
for key in list(six.iterkeys(stat_dict)):
if key not in keys:
del stat_dict[key]
for key in exclude_keys:
if key in stat_dict:
del stat_dict[key]
statstr_dict = stat_dict.copy()
if precision is not None:
assert ut.is_int(precision), 'precision must be an integer'
float_fmtstr = '%.' + str(precision) + 'f'
for key in list(six.iterkeys(statstr_dict)):
val = statstr_dict[key]
isfloat = ut.is_float(val)
if not isfloat and isinstance(val, list):
type_list = list(map(type, val))
if len(type_list) > 0 and ut.allsame(type_list):
if ut.is_float(val[0]):
isfloat = True
val = np.array(val)
if isfloat:
if isinstance(val, np.ndarray):
strval = str([float_fmtstr % v for v in val]).replace('\'', '').lstrip('u')
else:
strval = float_fmtstr % val
if not strval.startswith('0'):
strval = strval.rstrip('0')
strval = strval.rstrip('.')
statstr_dict[key] = strval
else:
if isinstance(val, np.ndarray):
strval = repr(val.tolist())
else:
strval = str(val)
statstr_dict[key] = strval
stat_str = repr4(statstr_dict, strvals=True, newlines=newlines)
if lbl is True:
lbl = ut.get_varname_from_stack(list_, N=1)
if lbl is not None:
stat_str = 'stats_' + lbl + ' = ' + stat_str
if align:
stat_str = ut.align(stat_str, ':')
return stat_str |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_module'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pat'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_seen'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '18', '29', '34', '42', '64', '149', '158']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_seen'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_seen'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '29', 'type': 'import_statement', 'children': ['30']}; {'id': '30', 'type': 'aliased_import', 'children': ['31', '33']}, {'id': '31', 'type': 'dotted_name', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reflags'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '41'], 'value': '*'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'found_list'}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '53']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '53', 'type': 'if_clause', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pat'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'reflags'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '66', 'type': 'block', 'children': ['67', '78', '85', '100', '128']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_seen'}; {'id': '70', 'type': 'None', 'children': []}, {'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': '_seen'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'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': '_seen'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'module_attrs'}; {'id': '88', 'type': 'list_comprehension', 'children': ['89', '94']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'submodules'}, {'id': '103', 'type': 'list_comprehension', 'children': ['104', '105', '108']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'submod'}, {'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'submod'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'module_attrs'}; {'id': '108', 'type': 'if_clause', 'children': ['109']}, {'id': '109', 'type': 'boolean_operator', 'children': ['110', '121'], 'value': 'and'}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '118'], 'value': 'and'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'submod'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'types'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ModuleType'}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'not'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'submod'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_seen'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'is_defined_by_module'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'submod'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'submod'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'submodules'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'augmented_assignment', 'children': ['134', '135'], 'value': '+='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'found_list'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'search_module'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '143', '146']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'submod'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'pat'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ignore_case'}, {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': '_seen'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_seen'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'found_list'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'unique_ordered'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'found_list'}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'found_list'} | def search_module(mod, pat, ignore_case=True, recursive=False, _seen=None):
r
if _seen is not None and mod in _seen:
return []
import utool as ut
reflags = re.IGNORECASE * ignore_case
found_list = [name for name in dir(mod) if re.search(pat, name, flags=reflags)]
if recursive:
if _seen is None:
_seen = set()
_seen.add(mod)
module_attrs = [getattr(mod, name) for name in dir(mod)]
submodules = [
submod for submod in module_attrs
if isinstance(submod, types.ModuleType) and submod not in _seen and
ut.is_defined_by_module(submod, mod)
]
for submod in submodules:
found_list += search_module(submod, pat, ignore_case=ignore_case, recursive=recursive, _seen=_seen)
found_list = ut.unique_ordered(found_list)
return found_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'instancelist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'check'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'shared_attrs'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '455']}; {'id': '12', 'type': 'class_definition', 'children': ['13', '14', '16']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'InstanceList_'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '16', 'type': 'block', 'children': ['17', '213', '250', '284', '311', '325', '366', '398', '433']}, {'id': '17', 'type': 'function_definition', 'children': ['18', '19', '25']}; {'id': '18', 'type': 'function_name', 'children': [], 'value': '__init__'}, {'id': '19', 'type': 'parameters', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'shared_attrs'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '32', '38', '44']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_obj_list'}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_shared_public_attrs'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_example_type'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '51']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '50'], 'value': '>'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '51', 'type': 'block', 'children': ['52', '57', '63', '69', '76', '82', '126', '130', '152']}; {'id': '52', 'type': 'import_statement', 'children': ['53']}, {'id': '53', 'type': 'aliased_import', 'children': ['54', '56']}; {'id': '54', 'type': 'dotted_name', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_obj_list'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'obj_list'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'example_obj'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'example_type'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'example_obj'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_example_type'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'example_type'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'shared_attrs'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'if_statement', 'children': ['88', '89', '117']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'check'}, {'id': '89', 'type': 'block', 'children': ['90', '104']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'attrsgen'}, {'id': '93', 'type': 'list_comprehension', 'children': ['94', '101']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'shared_attrs'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'attrsgen'}, {'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': 'shared_attrs'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'example_obj'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'allowed'}, {'id': '129', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_shared_public_attrs'}, {'id': '135', 'type': 'list_comprehension', 'children': ['136', '137', '140']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '137', 'type': 'for_in_clause', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'shared_attrs'}; {'id': '140', 'type': 'if_clause', 'children': ['141']}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'allowed'}, {'id': '145', 'type': 'not_operator', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '157']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_shared_public_attrs'}, {'id': '157', 'type': 'block', 'children': ['158', '167']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'attrtype'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'example_type'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'if_statement', 'children': ['168', '177', '193']}; {'id': '168', 'type': 'boolean_operator', 'children': ['169', '172'], 'value': 'and'}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'is'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'attrtype'}, {'id': '171', 'type': 'None', 'children': []}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'attrtype'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'property'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183', '184']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'InstanceList_'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'property'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_define_prop'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '193', 'type': 'else_clause', 'children': ['194']}; {'id': '194', 'type': 'block', 'children': ['195', '204']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_define_func'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'inject_func_as_method'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '213', 'type': 'function_definition', 'children': ['214', '215', '217']}; {'id': '214', 'type': 'function_name', 'children': [], 'value': '__nice__'}, {'id': '215', 'type': 'parameters', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'block', 'children': ['218', '239']}; {'id': '218', 'type': 'if_statement', 'children': ['219', '224', '229']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '223'], 'value': 'is'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': '_example_type'}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'object'"}, {'id': '229', 'type': 'else_clause', 'children': ['230']}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '234', 'type': 'attribute', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': '_example_type'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '239', 'type': 'return_statement', 'children': ['240']}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '%'}, {'id': '241', 'type': 'string', 'children': [], 'value': "'of %d %s(s)'"}; {'id': '242', 'type': 'tuple', 'children': ['243', '249']}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '_obj_list'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'typename'}; {'id': '250', 'type': 'function_definition', 'children': ['251', '252', '254']}, {'id': '251', 'type': 'function_name', 'children': [], 'value': '__repr__'}; {'id': '252', 'type': 'parameters', 'children': ['253']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'block', 'children': ['255', '263', '271']}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '258', 'type': 'attribute', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'devnice'}; {'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': '__nice__'}; {'id': '270', 'type': 'argument_list', 'children': []}, {'id': '271', 'type': 'return_statement', 'children': ['272']}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'}, {'id': '273', 'type': 'string', 'children': [], 'value': "'<%s(%s) at %s>'"}; {'id': '274', 'type': 'tuple', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'devnice'}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'hex'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '284', 'type': 'function_definition', 'children': ['285', '286', '288']}, {'id': '285', 'type': 'function_name', 'children': [], 'value': '__str__'}; {'id': '286', 'type': 'parameters', 'children': ['287']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'block', 'children': ['289', '297', '305']}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '292', 'type': 'attribute', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'devnice'}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': '__nice__'}; {'id': '304', 'type': 'argument_list', 'children': []}, {'id': '305', 'type': 'return_statement', 'children': ['306']}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '%'}, {'id': '307', 'type': 'string', 'children': [], 'value': "'<%s(%s)>'"}; {'id': '308', 'type': 'tuple', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'devnice'}, {'id': '311', 'type': 'function_definition', 'children': ['312', '313', '316']}; {'id': '312', 'type': 'function_name', 'children': [], 'value': '__getitem__'}, {'id': '313', 'type': 'parameters', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'return_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': '_map_method'}; {'id': '322', 'type': 'argument_list', 'children': ['323', '324']}, {'id': '323', 'type': 'string', 'children': [], 'value': "'__getitem__'"}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '325', 'type': 'function_definition', 'children': ['326', '327', '330']}; {'id': '326', 'type': 'function_name', 'children': [], 'value': '_define_func'}, {'id': '327', 'type': 'parameters', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '330', 'type': 'block', 'children': ['331', '336', '356', '364']}, {'id': '331', 'type': 'import_statement', 'children': ['332']}; {'id': '332', 'type': 'aliased_import', 'children': ['333', '335']}, {'id': '333', 'type': 'dotted_name', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '336', 'type': 'function_definition', 'children': ['337', '338', '344']}, {'id': '337', 'type': 'function_name', 'children': [], 'value': '_wrapper'}; {'id': '338', 'type': 'parameters', 'children': ['339', '340', '342']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'list_splat_pattern', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '342', 'type': 'dictionary_splat_pattern', 'children': ['343']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '344', 'type': 'block', 'children': ['345']}, {'id': '345', 'type': 'return_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': '_map_method'}; {'id': '350', 'type': 'argument_list', 'children': ['351', '352', '354']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '352', 'type': 'list_splat', 'children': ['353']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '354', 'type': 'dictionary_splat', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'set_funcname'}, {'id': '361', 'type': 'argument_list', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': '_wrapper'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '364', 'type': 'return_statement', 'children': ['365']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': '_wrapper'}; {'id': '366', 'type': 'function_definition', 'children': ['367', '368', '375']}, {'id': '367', 'type': 'function_name', 'children': [], 'value': '_map_method'}; {'id': '368', 'type': 'parameters', 'children': ['369', '370', '371', '373']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '371', 'type': 'list_splat_pattern', 'children': ['372']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '373', 'type': 'dictionary_splat_pattern', 'children': ['374']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '375', 'type': 'block', 'children': ['376', '396']}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'mapped_vals'}, {'id': '379', 'type': 'list_comprehension', 'children': ['380', '391']}; {'id': '380', 'type': 'call', 'children': ['381', '386']}, {'id': '381', 'type': 'call', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '383', 'type': 'argument_list', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '386', 'type': 'argument_list', 'children': ['387', '389']}, {'id': '387', 'type': 'list_splat', 'children': ['388']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '389', 'type': 'dictionary_splat', 'children': ['390']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '391', 'type': 'for_in_clause', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': '_obj_list'}; {'id': '396', 'type': 'return_statement', 'children': ['397']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'mapped_vals'}; {'id': '398', 'type': 'function_definition', 'children': ['399', '400', '403']}, {'id': '399', 'type': 'function_name', 'children': [], 'value': '_define_prop'}; {'id': '400', 'type': 'parameters', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '403', 'type': 'block', 'children': ['404', '409', '421', '431']}; {'id': '404', 'type': 'import_statement', 'children': ['405']}, {'id': '405', 'type': 'aliased_import', 'children': ['406', '408']}; {'id': '406', 'type': 'dotted_name', 'children': ['407']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '409', 'type': 'function_definition', 'children': ['410', '411', '413']}; {'id': '410', 'type': 'function_name', 'children': [], 'value': '_getter'}, {'id': '411', 'type': 'parameters', 'children': ['412']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '413', 'type': 'block', 'children': ['414']}; {'id': '414', 'type': 'return_statement', 'children': ['415']}, {'id': '415', 'type': 'call', 'children': ['416', '419']}; {'id': '416', 'type': 'attribute', 'children': ['417', '418']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': '_map_property'}, {'id': '419', 'type': 'argument_list', 'children': ['420']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '421', 'type': 'expression_statement', 'children': ['422']}; {'id': '422', 'type': 'call', 'children': ['423', '426']}, {'id': '423', 'type': 'attribute', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'set_funcname'}; {'id': '426', 'type': 'argument_list', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': '_getter'}; {'id': '428', 'type': 'binary_operator', 'children': ['429', '430'], 'value': '+'}, {'id': '429', 'type': 'string', 'children': [], 'value': "'get_'"}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '431', 'type': 'return_statement', 'children': ['432']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': '_getter'}, {'id': '433', 'type': 'function_definition', 'children': ['434', '435', '438']}; {'id': '434', 'type': 'function_name', 'children': [], 'value': '_map_property'}, {'id': '435', 'type': 'parameters', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '438', 'type': 'block', 'children': ['439', '453']}, {'id': '439', 'type': 'expression_statement', 'children': ['440']}; {'id': '440', 'type': 'assignment', 'children': ['441', '442']}, {'id': '441', 'type': 'identifier', 'children': [], 'value': 'mapped_vals'}; {'id': '442', 'type': 'list_comprehension', 'children': ['443', '448']}, {'id': '443', 'type': 'call', 'children': ['444', '445']}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '445', 'type': 'argument_list', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '448', 'type': 'for_in_clause', 'children': ['449', '450']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '450', 'type': 'attribute', 'children': ['451', '452']}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '452', 'type': 'identifier', 'children': [], 'value': '_obj_list'}, {'id': '453', 'type': 'return_statement', 'children': ['454']}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'mapped_vals'}, {'id': '455', 'type': 'return_statement', 'children': ['456']}; {'id': '456', 'type': 'call', 'children': ['457', '458']}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'InstanceList_'}; {'id': '458', 'type': 'argument_list', 'children': ['459', '460']}, {'id': '459', 'type': 'identifier', 'children': [], 'value': 'obj_list'} | def instancelist(obj_list, check=False, shared_attrs=None):
class InstanceList_(object):
def __init__(self, obj_list, shared_attrs=None):
self._obj_list = []
self._shared_public_attrs = []
self._example_type = None
if len(obj_list) > 0:
import utool as ut
self._obj_list = obj_list
example_obj = obj_list[0]
example_type = type(example_obj)
self._example_type = example_type
if shared_attrs is None:
if check:
attrsgen = [set(dir(obj)) for obj in obj_list]
shared_attrs = list(reduce(set.intersection, attrsgen))
else:
shared_attrs = dir(example_obj)
allowed = []
self._shared_public_attrs = [
a for a in shared_attrs
if a in allowed or not a.startswith('_')
]
for attrname in self._shared_public_attrs:
attrtype = getattr(example_type, attrname, None)
if attrtype is not None and isinstance(attrtype, property):
setattr(InstanceList_, attrname,
property(self._define_prop(attrname)))
else:
func = self._define_func(attrname)
ut.inject_func_as_method(self, func, attrname)
def __nice__(self):
if self._example_type is None:
typename = 'object'
else:
typename = self._example_type.__name__
return 'of %d %s(s)' % (len(self._obj_list), typename)
def __repr__(self):
classname = self.__class__.__name__
devnice = self.__nice__()
return '<%s(%s) at %s>' % (classname, devnice, hex(id(self)))
def __str__(self):
classname = self.__class__.__name__
devnice = self.__nice__()
return '<%s(%s)>' % (classname, devnice)
def __getitem__(self, key):
return self._map_method('__getitem__', key)
def _define_func(self, attrname):
import utool as ut
def _wrapper(self, *args, **kwargs):
return self._map_method(attrname, *args, **kwargs)
ut.set_funcname(_wrapper, attrname)
return _wrapper
def _map_method(self, attrname, *args, **kwargs):
mapped_vals = [getattr(obj, attrname)(*args, **kwargs)
for obj in self._obj_list]
return mapped_vals
def _define_prop(self, attrname):
import utool as ut
def _getter(self):
return self._map_property(attrname)
ut.set_funcname(_getter, 'get_' + attrname)
return _getter
def _map_property(self, attrname):
mapped_vals = [getattr(obj, attrname) for obj in self._obj_list]
return mapped_vals
return InstanceList_(obj_list, shared_attrs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_rows'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'merge_scalars'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '15', '26', '41', '56', '70', '83', '87', '301', '312', '318']}; {'id': '10', 'type': 'import_statement', 'children': ['11']}, {'id': '11', 'type': 'aliased_import', 'children': ['12', '14']}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'unique_labels'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'groupxs'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'group_indicies'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'single_xs'}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'groupxs'}; {'id': '34', 'type': 'if_clause', 'children': ['35']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': '=='}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'multi_xs'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '46', '49']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'xs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'groupxs'}, {'id': '49', 'type': 'if_clause', 'children': ['50']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '>'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'singles'}, {'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': 'take'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'single_xs'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'multis'}, {'id': '73', 'type': 'list_comprehension', 'children': ['74', '80']}; {'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': 'take'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'multi_xs'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'merged_groups'}; {'id': '86', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '87', 'type': 'for_statement', 'children': ['88', '89', '90']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'multis'}; {'id': '90', 'type': 'block', 'children': ['91', '95', '289']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'newgroup'}; {'id': '94', 'type': 'dictionary', 'children': []}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '102']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key_'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103', '109', '282']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'key_'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '113', '120', '143', '167', '187', '207']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'val_'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'elif_clause', 'children': ['121', '130']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'union'"}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'val_'}; {'id': '134', 'type': 'call', 'children': ['135', '140']}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'oset'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'list_splat', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '143', 'type': 'elif_clause', 'children': ['144', '154']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '150']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'tuple', 'children': ['151']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'oset'}; {'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': 'val_'}; {'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': 'ut'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'oset'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'list_splat', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '167', 'type': 'elif_clause', 'children': ['168', '176']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '174', 'type': 'parenthesized_expression', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'val_'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'list_splat', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '187', 'type': 'elif_clause', 'children': ['188', '197']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194']}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '194', 'type': 'tuple', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'val_'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '207', 'type': 'else_clause', 'children': ['208']}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'if_statement', 'children': ['210', '216', '223']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'allsame'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'val_'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '223', 'type': 'else_clause', 'children': ['224']}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'if_statement', 'children': ['226', '227', '232']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'merge_scalars'}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'val_'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '232', 'type': 'else_clause', 'children': ['233']}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'if_statement', 'children': ['235', '236', '271']}, {'id': '235', 'type': 'True', 'children': []}; {'id': '236', 'type': 'block', 'children': ['237', '246']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'other_vals'}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'filter_Nones'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '246', 'type': 'if_statement', 'children': ['247', '253', '260']}, {'id': '247', 'type': 'comparison_operator', 'children': ['248', '252'], 'value': '=='}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'other_vals'}; {'id': '252', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '253', 'type': 'block', 'children': ['254']}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'val_'}, {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'raise_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '%'}, {'id': '267', 'type': 'string', 'children': [], 'value': "'tried to merge a scalar in %r, val=%r'"}; {'id': '268', 'type': 'tuple', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'key_'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '271', 'type': 'else_clause', 'children': ['272']}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'raise_statement', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '%'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'tried to merge a scalar in %r, val=%r'"}, {'id': '279', 'type': 'tuple', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'key_'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '287']}; {'id': '284', 'type': 'subscript', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'newgroup'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'key_'}, {'id': '287', 'type': 'list', 'children': ['288'], 'value': '[val_]'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'val_'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'merged_groups'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ColumnLists'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'newgroup'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'merged_multi'}; {'id': '304', 'type': 'call', 'children': ['305', '310']}, {'id': '305', 'type': 'attribute', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'merged_groups'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '+'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'singles'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'merged_multi'}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'merged'} | def merge_rows(self, key, merge_scalars=True):
import utool as ut
unique_labels, groupxs = self.group_indicies(key)
single_xs = [xs for xs in groupxs if len(xs) == 1]
multi_xs = [xs for xs in groupxs if len(xs) > 1]
singles = self.take(ut.flatten(single_xs))
multis = [self.take(idxs) for idxs in multi_xs]
merged_groups = []
for group in multis:
newgroup = {}
for key_ in group.keys():
val = group[key_]
if key_ == key:
val_ = val[0]
elif hasattr(val[0].__class__, 'union'):
val_ = ut.oset.union(*val)
elif isinstance(val[0], (ut.oset,)):
val_ = ut.oset.union(*val)
elif isinstance(val[0], (set)):
val_ = set.union(*val)
elif isinstance(val[0], (tuple, list)):
val_ = ut.flatten(val)
else:
if ut.allsame(val):
val_ = val[0]
else:
if merge_scalars:
val_ = val
else:
if True:
other_vals = ut.filter_Nones(val)
if len(other_vals) == 1:
val_ = val[0]
else:
raise ValueError(
'tried to merge a scalar in %r, val=%r' % (
key_, val))
else:
raise ValueError(
'tried to merge a scalar in %r, val=%r' % (
key_, val))
newgroup[key_] = [val_]
merged_groups.append(ut.ColumnLists(newgroup))
merged_multi = self.__class__.flatten(merged_groups)
merged = singles + merged_multi
return merged |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '98', '115', '131', '145']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '7', '59']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': '_inject_execstr'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}, {'id': '7', 'type': 'ERROR', 'children': ['8', '31', '40', '41', '44', '46']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '21']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': '=='}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'utool'"}; {'id': '12', 'type': 'block', 'children': ['13', '17']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'injecter'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'util_inject'"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'injecter_import'}; {'id': '20', 'type': 'string', 'children': [], 'value': "''"}, {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23', '27']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'injecter_import'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'import utool'"}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'injecter'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'utool'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'injectstr_fmt'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'textwrap'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dedent'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "r'''\n {injecter_import}\n print, rrr, profile = {injecter}.inject2(__name__, '[{modname}]')\n def reassign_submodule_attributes(verbose=1):\n import sys\n if verbose and '--quiet' not in sys.argv:\n print('dev reimport')\n import {modname}\n seen_ = set([])\n for tup in IMPORT_TUPLES:\n if len(tup) > 2 and tup[2]:\n continue\n submodname, fromimports = tup[0:2]\n submod = getattr({modname}, submodname)\n for attr in dir(submod):\n if attr.startswith('_'):\n continue\n if attr in seen_:\n continue\n seen_.add(attr)\n setattr({modname}, attr, getattr(submod, attr))\n def reload_subs(verbose=1):\n if verbose:\n print('Reloading {modname} submodules')\n rrr(verbose > 1)\n def wrap_fbrrr(mod):\n def fbrrr(*args, **kwargs):\n if verbose > 0:\n print('Auto-reload (using rrr) not setup for mod=%r' % (mod,))\n return fbrrr\n def get_rrr(mod):\n if hasattr(mod, 'rrr'):\n return mod.rrr\n else:\n return wrap_fbrrr(mod)\n def get_reload_subs(mod):\n return getattr(mod, 'reload_subs', wrap_fbrrr(mod))\n {reload_body}\n rrr(verbose > 1)\n try:\n reassign_submodule_attributes(verbose=verbose)\n except Exception as ex:\n print(ex)\n rrrr = reload_subs\n '''"}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'injectstr_fmt'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'injectstr_fmt'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '44', 'type': 'ERROR', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'\n injectstr_fmt = injectstr_fmt.replace('"}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'rrrdir_fmt'}; {'id': '48', 'type': 'call', 'children': ['49', '54', '57']}, {'id': '49', 'type': 'concatenated_string', 'children': ['50', '51', '53']}; {'id': '50', 'type': 'string', 'children': [], 'value': "' get_reload_subs({modname})(verbose=verbose)'"}, {'id': '51', 'type': 'ERROR', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'rrrfile_fmt'}, {'id': '53', 'type': 'string', 'children': [], 'value': "' get_rrr({modname})(verbose > 1)'"}; {'id': '54', 'type': 'ERROR', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'def'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_reload_command'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '73', '85']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '68'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '67'], 'value': '>'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': 'is'}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '72', 'type': 'True', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'rrrdir_fmt'}; {'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': 'modname'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'rrrfile_fmt'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'reload_body'}, {'id': '101', 'type': 'call', 'children': ['102', '114']}; {'id': '102', 'type': 'attribute', 'children': ['103', '113']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_reload_command'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '114', 'type': 'argument_list', 'children': []}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'format_dict'}; {'id': '118', 'type': 'dictionary', 'children': ['119', '122', '125', '128']}, {'id': '119', 'type': 'pair', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'modname'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '122', 'type': 'pair', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'reload_body'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'reload_body'}, {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'injecter'"}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'injecter'}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'injecter_import'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'injecter_import'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'}; {'id': '134', 'type': 'call', 'children': ['135', '144']}, {'id': '135', 'type': 'attribute', 'children': ['136', '143']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'injectstr_fmt'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'dictionary_splat', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'format_dict'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '144', 'type': 'argument_list', 'children': []}, {'id': '145', 'type': 'return_statement', 'children': ['146']} | def _inject_execstr(modname, import_tuples):
if modname == 'utool':
injecter = 'util_inject'
injecter_import = ''
else:
injecter_import = 'import utool'
injecter = 'utool'
injectstr_fmt = textwrap.dedent(
r'''
{injecter_import}
print, rrr, profile = {injecter}.inject2(__name__, '[{modname}]')
def reassign_submodule_attributes(verbose=1):
import sys
if verbose and '--quiet' not in sys.argv:
print('dev reimport')
import {modname}
seen_ = set([])
for tup in IMPORT_TUPLES:
if len(tup) > 2 and tup[2]:
continue
submodname, fromimports = tup[0:2]
submod = getattr({modname}, submodname)
for attr in dir(submod):
if attr.startswith('_'):
continue
if attr in seen_:
continue
seen_.add(attr)
setattr({modname}, attr, getattr(submod, attr))
def reload_subs(verbose=1):
if verbose:
print('Reloading {modname} submodules')
rrr(verbose > 1)
def wrap_fbrrr(mod):
def fbrrr(*args, **kwargs):
if verbose > 0:
print('Auto-reload (using rrr) not setup for mod=%r' % (mod,))
return fbrrr
def get_rrr(mod):
if hasattr(mod, 'rrr'):
return mod.rrr
else:
return wrap_fbrrr(mod)
def get_reload_subs(mod):
return getattr(mod, 'reload_subs', wrap_fbrrr(mod))
{reload_body}
rrr(verbose > 1)
try:
reassign_submodule_attributes(verbose=verbose)
except Exception as ex:
print(ex)
rrrr = reload_subs
''')
injectstr_fmt = injectstr_fmt.replace('
injectstr_fmt = injectstr_fmt.replace('
rrrdir_fmt = ' get_reload_subs({modname})(verbose=verbose)'
rrrfile_fmt = ' get_rrr({modname})(verbose > 1)'
def _reload_command(tup):
if len(tup) > 2 and tup[2] is True:
return rrrdir_fmt.format(modname=tup[0])
else:
return rrrfile_fmt.format(modname=tup[0])
reload_body = '\n'.join(map(_reload_command, import_tuples)).strip()
format_dict = {
'modname': modname,
'reload_body': reload_body,
'injecter': injecter,
'injecter_import': injecter_import,
}
inject_execstr = injectstr_fmt.format(**format_dict).strip()
return inject_execstr |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '424']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '34']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'dynamic_import'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'developing'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ignore_froms'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dump'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ignore_startswith'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ignore_endswith'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ignore_list'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'check_not_imported'}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'return_initstr'}; {'id': '30', 'type': 'False', 'children': []}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '45', '64', '74', '84', '125', '133', '156', '167', '177', '220']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'[UTIL_IMPORT] Running Dynamic Imports for modname=%r '"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '45', 'type': 'try_statement', 'children': ['46', '55']}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '55', 'type': 'except_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '__import__'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'imports'}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '__excecute_imports'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80', '81']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'imports'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86', '111']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'developing'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'from_imports'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': '__execute_fromimport_star'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95', '96', '99', '102', '105', '108']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ignore_list'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ignore_list'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ignore_startswith'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ignore_startswith'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ignore_endswith'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ignore_endswith'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'check_not_imported'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'check_not_imported'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'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': 'from_imports'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '__execute_fromimport'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121', '122']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_inject_execstr'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'import_tuples'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dump_requested'}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '155'], 'value': 'or'}, {'id': '137', 'type': 'parenthesized_expression', 'children': ['138']}; {'id': '138', 'type': 'boolean_operator', 'children': ['139', '147'], 'value': 'or'}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '144'], 'value': 'in'}; {'id': '140', 'type': 'parenthesized_expression', 'children': ['141']}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'--dump-%s-init'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '152'], 'value': 'in'}; {'id': '148', 'type': 'parenthesized_expression', 'children': ['149']}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'--print-%s-init'"}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'overwrite_requested'}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': 'in'}; {'id': '160', 'type': 'parenthesized_expression', 'children': ['161']}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'--update-%s-init'"}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'[UTIL_IMPORT] Finished Dynamic Imports for modname=%r '"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'dump_requested'}, {'id': '179', 'type': 'block', 'children': ['180', '192']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'is_main_proc'}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '191'], 'value': '=='}; {'id': '184', 'type': 'attribute', 'children': ['185', '190']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'current_process'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'MainProcess'"}; {'id': '192', 'type': 'if_statement', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'is_main_proc'}; {'id': '194', 'type': 'block', 'children': ['195', '200', '210']}, {'id': '195', 'type': 'import_from_statement', 'children': ['196', '198']}; {'id': '196', 'type': 'dotted_name', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '198', 'type': 'dotted_name', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'initstr'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': '_initstr'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208', '209']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'imports'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'from_imports'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'initstr'}; {'id': '220', 'type': 'if_statement', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'overwrite_requested'}; {'id': '222', 'type': 'block', 'children': ['223', '235']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'is_main_proc'}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '234'], 'value': '=='}, {'id': '227', 'type': 'attribute', 'children': ['228', '233']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'current_process'}; {'id': '232', 'type': 'argument_list', 'children': []}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'MainProcess'"}, {'id': '235', 'type': 'if_statement', 'children': ['236', '237', '415']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'is_main_proc'}, {'id': '237', 'type': 'block', 'children': ['238', '243', '251', '264', '273', '285', '292', '297', '301', '305', '309', '380', '387', '396']}; {'id': '238', 'type': 'import_from_statement', 'children': ['239', '241']}, {'id': '239', 'type': 'dotted_name', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '241', 'type': 'dotted_name', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '243', 'type': 'import_from_statement', 'children': ['244', '247', '249']}; {'id': '244', 'type': 'dotted_name', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '247', 'type': 'dotted_name', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '249', 'type': 'dotted_name', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'initstr'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': '_initstr'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259', '260', '261']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'imports'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'from_imports'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'}, {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'withheader'}, {'id': '263', 'type': 'False', 'children': []}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'new_else'}, {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'initstr'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '278', 'type': 'argument_list', 'children': ['279', '284']}, {'id': '279', 'type': 'subscript', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': '__path__'}, {'id': '283', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '284', 'type': 'string', 'children': [], 'value': "'__init__.py'"}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'binary_operator', 'children': ['290', '291'], 'value': '%'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'attempting to update: %r'"}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}; {'id': '292', 'type': 'assert_statement', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'new_lines'}; {'id': '300', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'editing'}; {'id': '304', 'type': 'False', 'children': []}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'updated'}; {'id': '308', 'type': 'False', 'children': []}, {'id': '309', 'type': 'with_statement', 'children': ['310', '320']}; {'id': '310', 'type': 'with_clause', 'children': ['311']}, {'id': '311', 'type': 'with_item', 'children': ['312']}; {'id': '312', 'type': 'as_pattern', 'children': ['313', '318']}, {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '315', 'type': 'argument_list', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}, {'id': '317', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '318', 'type': 'as_pattern_target', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '320', 'type': 'block', 'children': ['321', '329', '366']}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '328', 'type': 'argument_list', 'children': []}, {'id': '329', 'type': 'for_statement', 'children': ['330', '331', '332', '357']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '332', 'type': 'ERROR', 'children': ['333', '344', '351', '356']}, {'id': '333', 'type': 'if_statement', 'children': ['334', '336']}; {'id': '334', 'type': 'not_operator', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'editing'}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'new_lines'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '344', 'type': 'attribute', 'children': ['345', '350']}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '349', 'type': 'argument_list', 'children': []}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '351', 'type': 'concatenated_string', 'children': ['352', '353', '355']}; {'id': '352', 'type': 'string', 'children': [], 'value': "'\n new_lines.append('"}, {'id': '353', 'type': 'ERROR', 'children': ['354']}; {'id': '354', 'type': 'escape_sequence', 'children': [], 'value': '\\n'}, {'id': '355', 'type': 'string', 'children': [], 'value': "' + new_else + '"}; {'id': '356', 'type': 'escape_sequence', 'children': [], 'value': '\\n'}, {'id': '357', 'type': 'block', 'children': ['358', '362']}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'assignment', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'editing'}, {'id': '361', 'type': 'True', 'children': []}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'assignment', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'updated'}, {'id': '365', 'type': 'True', 'children': []}; {'id': '366', 'type': 'if_statement', 'children': ['367', '374', '379']}, {'id': '367', 'type': 'attribute', 'children': ['368', '373']}; {'id': '368', 'type': 'call', 'children': ['369', '372']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '372', 'type': 'argument_list', 'children': []}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '374', 'type': 'ERROR', 'children': ['375', '376', '377', '378']}, {'id': '375', 'type': 'ERROR', 'children': []}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'editing'}, {'id': '377', 'type': 'False', 'children': []}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'updated'}, {'id': '379', 'type': 'block', 'children': [], 'value': ''}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}, {'id': '381', 'type': 'call', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '383', 'type': 'argument_list', 'children': ['384']}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '386'], 'value': '%'}, {'id': '385', 'type': 'string', 'children': [], 'value': "'writing updated file: %r'"}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}, {'id': '387', 'type': 'expression_statement', 'children': ['388']}; {'id': '388', 'type': 'assignment', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'new_text'}; {'id': '390', 'type': 'call', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'string', 'children': [], 'value': "''"}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'new_lines'}; {'id': '396', 'type': 'with_statement', 'children': ['397', '407']}, {'id': '397', 'type': 'with_clause', 'children': ['398']}; {'id': '398', 'type': 'with_item', 'children': ['399']}, {'id': '399', 'type': 'as_pattern', 'children': ['400', '405']}; {'id': '400', 'type': 'call', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '402', 'type': 'argument_list', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}; {'id': '404', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '405', 'type': 'as_pattern_target', 'children': ['406']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '407', 'type': 'block', 'children': ['408']}; {'id': '408', 'type': 'expression_statement', 'children': ['409']}, {'id': '409', 'type': 'call', 'children': ['410', '413']}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '413', 'type': 'argument_list', 'children': ['414']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'new_text'}, {'id': '415', 'type': 'else_clause', 'children': ['416']}; {'id': '416', 'type': 'block', 'children': ['417']}, {'id': '417', 'type': 'expression_statement', 'children': ['418']}; {'id': '418', 'type': 'call', 'children': ['419', '420']}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '420', 'type': 'argument_list', 'children': ['421']}, {'id': '421', 'type': 'binary_operator', 'children': ['422', '423'], 'value': '%'}; {'id': '422', 'type': 'string', 'children': [], 'value': "'no write hook for file: %r'"}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'init_fpath'}; {'id': '424', 'type': 'if_statement', 'children': ['425', '426', '444']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'return_initstr'}; {'id': '426', 'type': 'block', 'children': ['427', '440']}, {'id': '427', 'type': 'expression_statement', 'children': ['428']}; {'id': '428', 'type': 'assignment', 'children': ['429', '430']}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'initstr'}; {'id': '430', 'type': 'call', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': '_initstr'}; {'id': '432', 'type': 'argument_list', 'children': ['433', '434', '435', '436', '437']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'imports'}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'from_imports'}; {'id': '436', 'type': 'string', 'children': [], 'value': "''"}, {'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'withheader'}, {'id': '439', 'type': 'False', 'children': []}; {'id': '440', 'type': 'return_statement', 'children': ['441']}, {'id': '441', 'type': 'expression_list', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'initstr'}; {'id': '444', 'type': 'else_clause', 'children': ['445']}, {'id': '445', 'type': 'block', 'children': ['446']}; {'id': '446', 'type': 'return_statement', 'children': ['447']}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'inject_execstr'} | def dynamic_import(modname, import_tuples, developing=True, ignore_froms=[],
dump=False, ignore_startswith=[], ignore_endswith=[],
ignore_list=[], check_not_imported=True, return_initstr=False,
verbose=False):
if verbose:
print('[UTIL_IMPORT] Running Dynamic Imports for modname=%r ' % modname)
try:
module = sys.modules[modname]
except:
module = __import__(modname)
imports = [tup[0] for tup in import_tuples]
__excecute_imports(module, modname, imports, verbose=verbose)
if developing:
from_imports = __execute_fromimport_star(module, modname, import_tuples,
ignore_list=ignore_list,
ignore_startswith=ignore_startswith,
ignore_endswith=ignore_endswith,
check_not_imported=check_not_imported,
verbose=verbose)
else:
from_imports = __execute_fromimport(module, modname, import_tuples, verbose=verbose)
inject_execstr = _inject_execstr(modname, import_tuples)
dump_requested = (('--dump-%s-init' % modname) in sys.argv or
('--print-%s-init' % modname) in sys.argv) or dump
overwrite_requested = ('--update-%s-init' % modname) in sys.argv
if verbose:
print('[UTIL_IMPORT] Finished Dynamic Imports for modname=%r ' % modname)
if dump_requested:
is_main_proc = multiprocessing.current_process().name == 'MainProcess'
if is_main_proc:
from utool import util_str
initstr = _initstr(modname, imports, from_imports, inject_execstr)
print(util_str.indent(initstr))
if overwrite_requested:
is_main_proc = multiprocessing.current_process().name == 'MainProcess'
if is_main_proc:
from utool import util_str
from os.path import join, exists
initstr = _initstr(modname, imports, from_imports, inject_execstr, withheader=False)
new_else = util_str.indent(initstr)
init_fpath = join(module.__path__[0], '__init__.py')
print('attempting to update: %r' % init_fpath)
assert exists(init_fpath)
new_lines = []
editing = False
updated = False
with open(init_fpath, 'r') as file_:
lines = file_.readlines()
for line in lines:
if not editing:
new_lines.append(line)
if line.strip().startswith('
new_lines.append('\n' + new_else + '\n
editing = True
updated = True
if line.strip().startswith('
editing = False
if updated:
print('writing updated file: %r' % init_fpath)
new_text = ''.join(new_lines)
with open(init_fpath, 'w') as file_:
file_.write(new_text)
else:
print('no write hook for file: %r' % init_fpath)
if return_initstr:
initstr = _initstr(modname, imports, from_imports, '', withheader=False)
return inject_execstr, initstr
else:
return inject_execstr |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_to'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'to_write'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'aslines'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'onlyifdiff'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '54', '61', '74', '83', '96', '112']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'onlyifdiff'}; {'id': '24', 'type': 'block', 'children': ['25', '30']}, {'id': '25', 'type': 'import_statement', 'children': ['26']}; {'id': '26', 'type': 'aliased_import', 'children': ['27', '29']}, {'id': '27', 'type': 'dotted_name', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '47']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '41'], 'value': '=='}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'hashstr'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'read_from'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hashstr'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'to_write'}, {'id': '47', 'type': 'block', 'children': ['48', '53']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'[util_io] * no difference'"}, {'id': '53', 'type': 'return_statement', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_rectify_verb_write'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'[util_io] * Writing to text file: {}'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'backup'}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '79'], 'value': 'and'}; {'id': '78', 'type': 'False', 'children': []}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'backup'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'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': 'util_path'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '+'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'.backup'"}; {'id': '96', 'type': 'if_statement', 'children': ['97', '105']}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '112', 'type': 'with_statement', 'children': ['113', '123']}, {'id': '113', 'type': 'with_clause', 'children': ['114']}; {'id': '114', 'type': 'with_item', 'children': ['115']}, {'id': '115', 'type': 'as_pattern', 'children': ['116', '121']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '121', 'type': 'as_pattern_target', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '126', '134']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'aslines'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'writelines'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'to_write'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136', '157']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'PY2'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'if_statement', 'children': ['142', '147']}; {'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': 'to_write'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'unicode'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'to_write'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'to_write'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '157', 'type': 'try_statement', 'children': ['158', '166']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'to_write'}; {'id': '166', 'type': 'except_clause', 'children': ['167', '171']}, {'id': '167', 'type': 'as_pattern', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'UnicodeEncodeError'}, {'id': '169', 'type': 'as_pattern_target', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '171', 'type': 'block', 'children': ['172', '186', '196', '205', '213', '218', '223', '236', '242', '255']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '185']}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '184'], 'value': '-'}, {'id': '179', 'type': 'subscript', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '195'], 'value': '+'}; {'id': '190', 'type': 'subscript', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'to_write'}, {'id': '201', 'type': 'slice', 'children': ['202', '203', '204']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '203', 'type': 'colon', 'children': []}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'context'}, {'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': 'identifier', 'children': [], 'value': 'context'}; {'id': '218', 'type': 'import_from_statement', 'children': ['219', '221']}, {'id': '219', 'type': 'dotted_name', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '221', 'type': 'dotted_name', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'printex'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '232', 'type': 'list', 'children': ['233'], 'value': "[(type, 'to_write')]"}, {'id': '233', 'type': 'tuple', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '235', 'type': 'string', 'children': [], 'value': "'to_write'"}; {'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': 'file_'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '241', 'type': 'argument_list', 'children': []}; {'id': '242', 'type': 'if_statement', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'backup'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'util_path'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '254']}, {'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '+'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'.backup'"}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '255', 'type': 'raise_statement', 'children': []} | def write_to(fpath, to_write, aslines=False, verbose=None,
onlyifdiff=False, mode='w', n=None):
if onlyifdiff:
import utool as ut
if ut.hashstr(read_from(fpath)) == ut.hashstr(to_write):
print('[util_io] * no difference')
return
verbose = _rectify_verb_write(verbose)
if verbose:
print('[util_io] * Writing to text file: {}'.format(fpath))
backup = False and exists(fpath)
if backup:
util_path.copy(fpath, fpath + '.backup')
if not isinstance(fpath, six.string_types):
fpath = fpath.name
with open(fpath, mode) as file_:
if aslines:
file_.writelines(to_write)
else:
if six.PY2:
if isinstance(to_write, unicode):
to_write = to_write.encode('utf8')
try:
file_.write(to_write)
except UnicodeEncodeError as ex:
start = max(ex.args[2] - 10, 0)
end = ex.args[3] + 10
context = to_write[start:end]
print(repr(context))
print(context)
from utool import util_dbg
util_dbg.printex(ex, keys=[(type, 'to_write')])
file_.close()
if backup:
util_path.copy(fpath + '.backup', fpath)
raise |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_from'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'aslines'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'replace'"}; {'id': '20', 'type': 'block', 'children': ['21', '23', '32', '39', '57']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '__READ_TAIL_N__'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_rectify_verb_read'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'[util_io] * Reading text file: %r '"}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'util_path'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '57', 'type': 'try_statement', 'children': ['58', '184']}; {'id': '58', 'type': 'block', 'children': ['59', '79', '182']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '73']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'util_path'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '70']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'n'}, {'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': 'IOError'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'[io] * FILE DOES NOT EXIST!'"}, {'id': '79', 'type': 'with_statement', 'children': ['80', '90']}; {'id': '80', 'type': 'with_clause', 'children': ['81']}, {'id': '81', 'type': 'with_item', 'children': ['82']}; {'id': '82', 'type': 'as_pattern', 'children': ['83', '88']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '88', 'type': 'as_pattern_target', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93', '141']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'aslines'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '98', '119']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'PY2'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '112']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'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': 'text'}; {'id': '124', 'type': 'list_comprehension', 'children': ['125', '134']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147', '164']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '151', 'type': 'call', 'children': ['152', '159']}; {'id': '152', 'type': 'attribute', 'children': ['153', '158']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '169', 'type': 'call', 'children': ['170', '177']}; {'id': '170', 'type': 'attribute', 'children': ['171', '176']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '182', 'type': 'return_statement', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '184', 'type': 'except_clause', 'children': ['185', '189']}, {'id': '185', 'type': 'as_pattern', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '187', 'type': 'as_pattern_target', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '189', 'type': 'block', 'children': ['190', '195', '219']}; {'id': '190', 'type': 'import_from_statement', 'children': ['191', '193']}, {'id': '191', 'type': 'dotted_name', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '193', 'type': 'dotted_name', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '195', 'type': 'if_statement', 'children': ['196', '199']}; {'id': '196', 'type': 'boolean_operator', 'children': ['197', '198'], 'value': 'or'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'printex'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '218']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '%'}; {'id': '208', 'type': 'string', 'children': [], 'value': "' * Error reading fpath=%r'"}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'util_path'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'[io]'"}, {'id': '219', 'type': 'if_statement', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '221', 'type': 'block', 'children': ['222']} | def read_from(fpath, verbose=None, aslines=False, strict=True, n=None, errors='replace'):
r
if n is None:
n = __READ_TAIL_N__
verbose = _rectify_verb_read(verbose)
if verbose:
print('[util_io] * Reading text file: %r ' % util_path.tail(fpath, n=n))
try:
if not util_path.checkpath(fpath, verbose=verbose, n=n):
raise IOError('[io] * FILE DOES NOT EXIST!')
with open(fpath, 'rb') as file_:
if aslines:
if six.PY2:
text = [line.decode('utf8', errors=errors)
for line in file_.readlines()]
else:
text = [line.decode('utf8', errors=errors)
for line in file_.readlines()]
else:
if six.PY2:
text = file_.read().decode('utf8', errors=errors)
else:
text = file_.read().decode('utf8', errors=errors)
return text
except IOError as ex:
from utool import util_dbg
if verbose or strict:
util_dbg.printex(ex, ' * Error reading fpath=%r' %
util_path.tail(fpath, n=n), '[io]')
if strict:
raise |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_cPkl'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '38', '130']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_rectify_verb_read'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'[util_io] * load_cPkl(%r)'"}; {'id': '28', 'type': 'tuple', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'util_path'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '38', 'type': 'try_statement', 'children': ['39', '61', '96']}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'with_statement', 'children': ['41', '51']}, {'id': '41', 'type': 'with_clause', 'children': ['42']}; {'id': '42', 'type': 'with_item', 'children': ['43']}, {'id': '43', 'type': 'as_pattern', 'children': ['44', '49']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'rb'"}, {'id': '49', 'type': 'as_pattern_target', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '61', 'type': 'except_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68', '93']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'with_statement', 'children': ['70', '80']}; {'id': '70', 'type': 'with_clause', 'children': ['71']}, {'id': '71', 'type': 'with_item', 'children': ['72']}; {'id': '72', 'type': 'as_pattern', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '78', 'type': 'as_pattern_target', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'pickle'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'latin1'"}, {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'raise_statement', 'children': []}; {'id': '96', 'type': 'except_clause', 'children': ['97', '101']}, {'id': '97', 'type': 'as_pattern', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '99', 'type': 'as_pattern_target', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106', '127']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'PY2'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'if_statement', 'children': ['108', '113', '124']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '112'], 'value': '=='}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'unsupported pickle protocol: 4'"}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'raise_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '%'}, {'id': '119', 'type': 'concatenated_string', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'unsupported Python3 pickle protocol 4 '"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'in Python2 for fpath=%r'"}; {'id': '122', 'type': 'tuple', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '124', 'type': 'else_clause', 'children': ['125']}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'raise_statement', 'children': []}, {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'raise_statement', 'children': []}; {'id': '130', 'type': 'return_statement', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'} | def load_cPkl(fpath, verbose=None, n=None):
verbose = _rectify_verb_read(verbose)
if verbose:
print('[util_io] * load_cPkl(%r)' % (util_path.tail(fpath, n=n),))
try:
with open(fpath, 'rb') as file_:
data = pickle.load(file_)
except UnicodeDecodeError:
if six.PY3:
with open(fpath, 'rb') as file_:
data = pickle.load(file_, encoding='latin1')
else:
raise
except ValueError as ex:
if six.PY2:
if ex.message == 'unsupported pickle protocol: 4':
raise ValueError(
'unsupported Python3 pickle protocol 4 '
'in Python2 for fpath=%r' % (fpath,))
else:
raise
else:
raise
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_hdf5'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'compression'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'lzf'"}; {'id': '12', 'type': 'block', 'children': ['13', '15', '18', '25', '41', '83', '87', '94', '98']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '15', 'type': 'import_statement', 'children': ['16']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'h5py'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_rectify_verb_write'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '%'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'[util_io] * save_hdf5(%r, data)'"}; {'id': '34', 'type': 'tuple', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'util_path'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '>'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '71']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'[util_io] ... shapes=%r'"}, {'id': '59', 'type': 'tuple', 'children': ['60']}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'[util_io] ... shape=%r'"}, {'id': '79', 'type': 'tuple', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '86', 'type': 'True', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'h5kw'}, {'id': '97', 'type': 'dictionary', 'children': []}; {'id': '98', 'type': 'if_statement', 'children': ['99', '104', '244']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '104', 'type': 'block', 'children': ['105', '131', '151']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'array_data'}; {'id': '108', 'type': 'dictionary_comprehension', 'children': ['109', '112', '121']}, {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '116']}, {'id': '113', 'type': 'pattern_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'if_clause', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '126', 'type': 'tuple', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ndarray'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'attr_data'}; {'id': '134', 'type': 'dictionary_comprehension', 'children': ['135', '138', '147']}, {'id': '135', 'type': 'pair', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '138', 'type': 'for_in_clause', 'children': ['139', '142']}, {'id': '139', 'type': 'pattern_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '146', 'type': 'argument_list', 'children': []}, {'id': '147', 'type': 'if_clause', 'children': ['148']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'not'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'array_data'}, {'id': '151', 'type': 'with_statement', 'children': ['152', '168']}; {'id': '152', 'type': 'with_clause', 'children': ['153']}, {'id': '153', 'type': 'with_item', 'children': ['154']}; {'id': '154', 'type': 'as_pattern', 'children': ['155', '166']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'h5py'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'File'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161', '164']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '164', 'type': 'dictionary_splat', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'h5kw'}; {'id': '166', 'type': 'as_pattern_target', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '168', 'type': 'block', 'children': ['169', '178', '225']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'grp'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'create_group'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '178', 'type': 'for_statement', 'children': ['179', '182', '188']}, {'id': '179', 'type': 'pattern_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'array_data'}; {'id': '188', 'type': 'block', 'children': ['189', '198', '219']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'dset'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'grp'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'create_dataset'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '210', '213', '216']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'chunks'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'compression'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'compression'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'dset'}, {'id': '223', 'type': 'ellipsis', 'children': [], 'value': '...'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '225', 'type': 'for_statement', 'children': ['226', '229', '235']}; {'id': '226', 'type': 'pattern_list', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'attr_data'}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '243']}; {'id': '238', 'type': 'subscript', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'grp'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246', '254', '260', '266']}; {'id': '246', 'type': 'assert_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '266', 'type': 'with_statement', 'children': ['267', '283']}, {'id': '267', 'type': 'with_clause', 'children': ['268']}; {'id': '268', 'type': 'with_item', 'children': ['269']}, {'id': '269', 'type': 'as_pattern', 'children': ['270', '281']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'h5py'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'File'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '276', '279']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '279', 'type': 'dictionary_splat', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'h5kw'}, {'id': '281', 'type': 'as_pattern_target', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'file_'}, {'id': '283', 'type': 'block', 'children': ['284', '301']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'dset'}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'file_'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'create_dataset'}, {'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '295', '298']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'chunks'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'compression'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'compression'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '306']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'dset'}, {'id': '305', 'type': 'ellipsis', 'children': [], 'value': '...'} | def save_hdf5(fpath, data, verbose=None, compression='lzf'):
r
import h5py
verbose = _rectify_verb_write(verbose)
if verbose:
print('[util_io] * save_hdf5(%r, data)' % (util_path.tail(fpath),))
if verbose > 1:
if isinstance(data, dict):
print('[util_io] ... shapes=%r' % ([val.shape for val in data.values()],))
else:
print('[util_io] ... shape=%r' % (data.shape,))
chunks = True
fname = basename(fpath)
h5kw = {}
if isinstance(data, dict):
array_data = {key: val for key, val in data.items()
if isinstance(val, (list, np.ndarray))}
attr_data = {key: val for key, val in data.items() if key not in array_data}
with h5py.File(fpath, mode='w', **h5kw) as file_:
grp = file_.create_group(fname)
for key, val in six.iteritems(array_data):
val = np.asarray(val)
dset = grp.create_dataset(
key, val.shape, val.dtype, chunks=chunks,
compression=compression)
dset[...] = val
for key, val in six.iteritems(attr_data):
grp.attrs[key] = val
else:
assert isinstance(data, np.ndarray)
shape = data.shape
dtype = data.dtype
with h5py.File(fpath, mode='w', **h5kw) as file_:
dset = file_.create_dataset(
fname, shape, dtype, chunks=chunks, compression=compression)
dset[...] = data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'formatex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'[!?] Caught exception'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key_list'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'iswarning'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tb'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'colored'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '35', '52', '68', '77', '81', '88', '97', '142', '172', '180', '189']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_caller_prefix'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '49']}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'aserror'}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'locals_'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '60', 'type': 'attribute', 'children': ['61', '67']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_parent_frame'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'f_locals'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'key_list'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'errstr_list'}; {'id': '80', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ex_tag'}; {'id': '84', 'type': 'conditional_expression', 'children': ['85', '86', '87'], 'value': 'if'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'WARNING'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'iswarning'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'EXCEPTION'"}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'errstr_list'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'<!!! %s !!!>'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ex_tag'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '100'], 'value': 'or'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tb'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'FORCE_TB'}, {'id': '101', 'type': 'block', 'children': ['102', '110', '135']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'tbtext'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'traceback'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'format_exc'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '113'], 'value': 'or'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'colored'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'COLORED_EXCEPTIONS'}; {'id': '114', 'type': 'block', 'children': ['115', '120']}, {'id': '115', 'type': 'import_from_statement', 'children': ['116', '118']}; {'id': '116', 'type': 'dotted_name', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '118', 'type': 'dotted_name', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'tbtext'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'highlight_text'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129', '132']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'tbtext'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'lexer_name'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'pytb'"}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'stripall'}; {'id': '134', 'type': 'True', 'children': []}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'errstr_list'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tbtext'}; {'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': 'errstr_list'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '159'], 'value': '+'}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '153'], 'value': '+'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '152', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'\\n%r: %s'"}, {'id': '161', 'type': 'tuple', 'children': ['162', '166']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'parse_locals_keylist'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '179']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'locals_'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'key_list'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'errstr_list'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'errstr_list'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'</!!! %s !!!>'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ex_tag'}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'errstr_list'} | def formatex(ex, msg='[!?] Caught exception',
prefix=None, key_list=[], locals_=None, iswarning=False, tb=False,
N=0, keys=None, colored=None):
r
if prefix is None:
prefix = get_caller_prefix(aserror=True, N=N)
if locals_ is None:
locals_ = get_parent_frame(N=N).f_locals
if keys is not None:
key_list = keys
errstr_list = []
ex_tag = 'WARNING' if iswarning else 'EXCEPTION'
errstr_list.append('<!!! %s !!!>' % ex_tag)
if tb or FORCE_TB:
tbtext = traceback.format_exc()
if colored or COLORED_EXCEPTIONS:
from utool import util_str
tbtext = util_str.highlight_text(tbtext, lexer_name='pytb', stripall=True)
errstr_list.append(tbtext)
errstr_list.append(prefix + ' ' + six.text_type(msg) + '\n%r: %s' % (type(ex), six.text_type(ex)))
parse_locals_keylist(locals_, key_list, errstr_list, prefix)
errstr_list.append('</!!! %s !!!>' % ex_tag)
return '\n'.join(errstr_list) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__send_rdy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '7', 'type': 'block', 'children': ['8', '265', '284', '294', '300', '308', '326', '351']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16', '209']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': 'is'}; {'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': '__consumer'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'original_rdy'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '32', '49']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'node_count'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_node_count_for_topic'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'topic'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43', '48']}; {'id': '40', 'type': 'concatenated_string', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': '"Calculating RDY: max_in_flight=(%d) "'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"node_count=(%d)"'}, {'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': '__consumer'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'node_count'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '57', '101']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '56'], 'value': '>='}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'node_count'}, {'id': '57', 'type': 'block', 'children': ['58', '82']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'math'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ceil'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '78'], 'value': '/'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'node_count'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '94', '99', '100']}; {'id': '90', 'type': 'concatenated_string', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'string', 'children': [], 'value': '"Assigning RDY based on max_in_flight "'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"(%d) and node count (%d) (optimal): "'}, {'id': '93', 'type': 'string', 'children': [], 'value': '"(%d)"'}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '__consumer'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'node_count'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103', '114', '141', '151', '205']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'concatenated_string', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"(max_in_flight > nodes). Doing RDY "'}, {'id': '113', 'type': 'string', 'children': [], 'value': '"election."'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sleeping_connections'}, {'id': '117', 'type': 'list_comprehension', 'children': ['118', '119', '120', '134', '135']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '119', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '120', 'type': 'for_in_clause', 'children': ['121', '124', '125']}, {'id': '121', 'type': 'tuple_pattern', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '124', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '125', 'type': 'call', 'children': ['126', '133']}; {'id': '126', 'type': 'attribute', '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': '__consumer'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'connection_context'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '135', 'type': 'if_clause', 'children': ['136']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': '=='}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'rdy_count'"}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '148']}, {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': '"Current sleeping_connections: %s"'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'sleeping_connections'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '153', '191']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sleeping_connections'}, {'id': '153', 'type': 'block', 'children': ['154', '163', '173', '184']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'elected_connection'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'choice'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sleeping_connections'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '170']}, {'id': '165', 'type': 'attribute', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': '"Sending RDY of (1) on: [%s]"'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'elected_connection'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'command_elected'}; {'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': 'nsq'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'Command'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'elected_connection'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'command_elected'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'rdy'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '191', 'type': 'else_clause', 'children': ['192']}; {'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': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '__logger'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '204']}, {'id': '201', 'type': 'concatenated_string', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': '"No sleeping connections. We got the "'}, {'id': '203', 'type': 'string', 'children': [], 'value': '"short stick: [%s]"'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '209', 'type': 'else_clause', 'children': ['210']}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'try_statement', 'children': ['212', '244']}; {'id': '212', 'type': 'block', 'children': ['213', '234']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '216', 'type': 'call', 'children': ['217', '222']}, {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'original_rdy'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '226', '231']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'node'}; {'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': '__consumer'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'connection_count'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '__consumer'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': '"Using RDY from callback: (%d)"'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '244', 'type': 'except_clause', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '246', 'type': 'block', 'children': ['247', '255']}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '250', 'type': 'attribute', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': '__consumer'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'original_rdy'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '262']}, {'id': '257', 'type': 'attribute', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '264']}, {'id': '263', 'type': 'string', 'children': [], 'value': '"Using static RDY: (%d)"'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '270', 'type': 'argument_list', 'children': ['271', '279']}, {'id': '271', 'type': 'binary_operator', 'children': ['272', '273', '274'], 'value': '+'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '273', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': '__get_total_rdy_count'}; {'id': '278', 'type': 'argument_list', 'children': []}, {'id': '279', 'type': 'attribute', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'server_features'}, {'id': '287', 'type': 'attribute', 'children': ['288', '293']}; {'id': '288', 'type': 'attribute', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': '__consumer'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'identify'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'server_features'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'max_rdy_count'}, {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'server_features'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'max_rdy_count'"}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'max_rdy_count'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'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': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '315', 'type': 'argument_list', 'children': ['316', '319', '324', '325']}; {'id': '316', 'type': 'concatenated_string', 'children': ['317', '318']}, {'id': '317', 'type': 'string', 'children': [], 'value': '"Final RDY (max_in_flight=(%d) "'}; {'id': '318', 'type': 'string', 'children': [], 'value': '"max_rdy_count=(%d)): (%d)"'}, {'id': '319', 'type': 'attribute', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': '__consumer'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'max_in_flight'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'max_rdy_count'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '326', 'type': 'if_statement', 'children': ['327', '330', '338']}, {'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': '>'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}, {'id': '329', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'rdy'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'rdy_this'}; {'id': '338', 'type': 'else_clause', 'children': ['339']}, {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'call', 'children': ['342', '347']}; {'id': '342', 'type': 'attribute', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': '__logger_rdy'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'concatenated_string', 'children': ['349', '350']}, {'id': '349', 'type': 'string', 'children': [], 'value': '"This connection will go to sleep (not "'}; {'id': '350', 'type': 'string', 'children': [], 'value': '"enough RDY to go around)."'}, {'id': '351', 'type': 'return_statement', 'children': ['352']} | def __send_rdy(self, connection, command):
if self.__consumer.original_rdy is None:
node_count = self.__consumer.get_node_count_for_topic(
connection.context.topic)
self.__logger_rdy.debug("Calculating RDY: max_in_flight=(%d) "
"node_count=(%d)",
self.__consumer.max_in_flight, node_count)
if self.__consumer.max_in_flight >= node_count:
rdy_this = int(math.ceil(
float(self.__consumer.max_in_flight) /
float(node_count)))
self.__logger_rdy.debug("Assigning RDY based on max_in_flight "
"(%d) and node count (%d) (optimal): "
"(%d)",
self.__consumer.max_in_flight,
node_count, rdy_this)
else:
self.__logger_rdy.debug("(max_in_flight > nodes). Doing RDY "
"election.")
sleeping_connections = [
c \
for (c, info) \
in self.__consumer.connection_context.items() \
if info['rdy_count'] == 0]
self.__logger_rdy.debug("Current sleeping_connections: %s",
sleeping_connections)
if sleeping_connections:
elected_connection = random.choice(sleeping_connections)
self.__logger_rdy.debug("Sending RDY of (1) on: [%s]",
elected_connection)
command_elected = nsq.command.Command(elected_connection)
command_elected.rdy(1)
else:
self.__logger.debug("No sleeping connections. We got the "
"short stick: [%s]", connection)
rdy_this = 0
else:
try:
rdy_this = self.__consumer.original_rdy(
connection.node,
self.__consumer.connection_count,
self.__consumer)
self.__logger_rdy.debug("Using RDY from callback: (%d)",
rdy_this)
except TypeError:
rdy_this = self.__consumer.original_rdy
self.__logger_rdy.debug("Using static RDY: (%d)", rdy_this)
rdy_this = min(rdy_this + \
self.__get_total_rdy_count(),
self.__consumer.max_in_flight)
server_features = self.__consumer.identify.server_features
max_rdy_count = server_features['max_rdy_count']
rdy_this = min(max_rdy_count, rdy_this)
self.__logger_rdy.debug("Final RDY (max_in_flight=(%d) "
"max_rdy_count=(%d)): (%d)",
self.__consumer.max_in_flight, max_rdy_count,
rdy_this)
if rdy_this > 0:
command.rdy(rdy_this)
else:
self.__logger_rdy.info("This connection will go to sleep (not "
"enough RDY to go around).")
return rdy_this |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_instruction'}, {'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', '14', '23', '52']}, {'id': '7', 'type': 'assert_statement', 'children': ['8']}; {'id': '8', 'type': 'parenthesized_expression', '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': 'instr'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Instruction'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'instruction_list'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '31']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'not'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'lhs'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'defined_variables'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '40']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'lhs'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Variable'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'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': 'defined_variables'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lhs'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '58', '88']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'EqInstruction'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '67']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rhs'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Variable'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': 'not'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'rhs'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'used_variables'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'used_variables'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'rhs'}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90', '119']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '98']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'rhs_1'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Variable'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '107']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'not'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'rhs_1'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'used_variables'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'used_variables'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'rhs_1'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '127']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rhs_2'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'Variable'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '136']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'not'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'rhs_2'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'used_variables'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '144']}, {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'used_variables'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'rhs_2'} | def add_instruction (self, instr):
assert(isinstance(instr, Instruction))
self.instruction_list.append(instr)
if instr.lhs not in self.defined_variables:
if isinstance(instr.lhs, Variable):
self.defined_variables.append(instr.lhs)
if isinstance(instr, EqInstruction):
if isinstance(instr.rhs, Variable):
if instr.rhs not in self.used_variables:
self.used_variables.append(instr.rhs)
else:
if isinstance(instr.rhs_1, Variable):
if instr.rhs_1 not in self.used_variables:
self.used_variables.append(instr.rhs_1)
if isinstance(instr.rhs_2, Variable):
if instr.rhs_2 not in self.used_variables:
self.used_variables.append(instr.rhs_2) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tokenize'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '22', '26', '30', '50']}; {'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': 'token_list'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parse_string'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'last_token'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'while_statement', 'children': ['31', '45']}, {'id': '31', 'type': 'boolean_operator', 'children': ['32', '38'], 'value': 'and'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '<'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isspace'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'while_statement', 'children': ['51', '57']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '<'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '57', 'type': 'block', 'children': ['58', '62', '304', '330', '337', '341']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '61', 'type': 'string', 'children': [], 'value': "''"}; {'id': '62', 'type': 'if_statement', 'children': ['63', '70', '104', '206', '292']}, {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isalpha'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'while_statement', 'children': ['72', '93']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '79'], 'value': 'and'}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '<'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '79', 'type': 'parenthesized_expression', 'children': ['80']}; {'id': '80', 'type': 'boolean_operator', 'children': ['81', '88'], 'value': 'or'}, {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'isalnum'}, {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '93', 'type': 'block', 'children': ['94', '100']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'augmented_assignment', 'children': ['96', '97'], 'value': '+='}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'augmented_assignment', 'children': ['102', '103'], 'value': '+='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'elif_clause', 'children': ['105', '112']}, {'id': '105', 'type': 'call', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'isdigit'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'while_statement', 'children': ['114', '195']}; {'id': '114', 'type': 'boolean_operator', 'children': ['115', '121'], 'value': 'and'}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '<'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'ps'}, {'id': '121', 'type': 'parenthesized_expression', 'children': ['122']}; {'id': '122', 'type': 'boolean_operator', 'children': ['123', '172'], 'value': 'or'}, {'id': '123', 'type': 'boolean_operator', 'children': ['124', '149'], 'value': 'or'}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '144'], 'value': 'or'}, {'id': '125', 'type': 'boolean_operator', 'children': ['126', '139'], 'value': 'or'}; {'id': '126', 'type': 'boolean_operator', 'children': ['127', '134'], 'value': 'or'}, {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'isdigit'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': '=='}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': '=='}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'e'"}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': '=='}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'E'"}, {'id': '149', 'type': 'parenthesized_expression', 'children': ['150']}; {'id': '150', 'type': 'boolean_operator', 'children': ['151', '156'], 'value': 'and'}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': '=='}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '156', 'type': 'parenthesized_expression', 'children': ['157']}, {'id': '157', 'type': 'boolean_operator', 'children': ['158', '165'], 'value': 'or'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '=='}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '-'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'e'"}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '171'], 'value': '=='}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '-'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '171', 'type': 'string', 'children': [], 'value': "'E'"}; {'id': '172', 'type': 'parenthesized_expression', 'children': ['173']}, {'id': '173', 'type': 'boolean_operator', 'children': ['174', '179'], 'value': 'and'}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '179', 'type': 'parenthesized_expression', 'children': ['180']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '188'], 'value': 'or'}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '187'], 'value': '=='}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '-'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'e'"}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '194'], 'value': '=='}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '-'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'E'"}, {'id': '195', 'type': 'block', 'children': ['196', '202']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '+='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'augmented_assignment', 'children': ['204', '205'], 'value': '+='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'elif_clause', 'children': ['207', '212']}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '211'], 'value': '=='}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'if_statement', 'children': ['214', '223', '257']}; {'id': '214', 'type': 'call', 'children': ['215', '222']}, {'id': '215', 'type': 'attribute', 'children': ['216', '221']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '222', 'type': 'argument_list', 'children': []}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'while_statement', 'children': ['225', '246']}, {'id': '225', 'type': 'boolean_operator', 'children': ['226', '232'], 'value': 'and'}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '<'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '232', 'type': 'parenthesized_expression', 'children': ['233']}, {'id': '233', 'type': 'boolean_operator', 'children': ['234', '241'], 'value': 'or'}; {'id': '234', 'type': 'call', 'children': ['235', '240']}, {'id': '235', 'type': 'attribute', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '240', 'type': 'argument_list', 'children': []}, {'id': '241', 'type': 'comparison_operator', 'children': ['242', '245'], 'value': '=='}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '246', 'type': 'block', 'children': ['247', '253']}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'augmented_assignment', 'children': ['249', '250'], 'value': '+='}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'augmented_assignment', 'children': ['255', '256'], 'value': '+='}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '257', 'type': 'else_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'while_statement', 'children': ['260', '281']}; {'id': '260', 'type': 'boolean_operator', 'children': ['261', '267'], 'value': 'and'}, {'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': '<'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '267', 'type': 'parenthesized_expression', 'children': ['268']}; {'id': '268', 'type': 'boolean_operator', 'children': ['269', '276'], 'value': 'or'}, {'id': '269', 'type': 'call', 'children': ['270', '275']}; {'id': '270', 'type': 'attribute', 'children': ['271', '274']}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'isalpha'}, {'id': '275', 'type': 'argument_list', 'children': []}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '=='}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '281', 'type': 'block', 'children': ['282', '288']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'augmented_assignment', 'children': ['284', '285'], 'value': '+='}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'augmented_assignment', 'children': ['290', '291'], 'value': '+='}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '291', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '292', 'type': 'else_clause', 'children': ['293']}, {'id': '293', 'type': 'block', 'children': ['294', '300']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'augmented_assignment', 'children': ['296', '297'], 'value': '+='}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'augmented_assignment', 'children': ['302', '303'], 'value': '+='}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '303', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '304', 'type': 'if_statement', 'children': ['305', '325']}, {'id': '305', 'type': 'boolean_operator', 'children': ['306', '309', '310'], 'value': 'and'}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': '=='}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '309', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '310', 'type': 'parenthesized_expression', 'children': ['311']}, {'id': '311', 'type': 'boolean_operator', 'children': ['312', '319'], 'value': 'or'}; {'id': '312', 'type': 'boolean_operator', 'children': ['313', '316'], 'value': 'or'}, {'id': '313', 'type': 'comparison_operator', 'children': ['314', '315'], 'value': '=='}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'last_token'}, {'id': '315', 'type': 'None', 'children': []}; {'id': '316', 'type': 'comparison_operator', 'children': ['317', '318'], 'value': '=='}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '318', 'type': 'string', 'children': [], 'value': "'('"}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'is_op'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'last_token'}, {'id': '325', 'type': 'block', 'children': ['326']}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'assignment', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '329', 'type': 'string', 'children': [], 'value': "'~'"}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'augmented_assignment', 'children': ['332', '335'], 'value': '+='}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'token_list'}, {'id': '335', 'type': 'list', 'children': ['336'], 'value': '[token]'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'assignment', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '341', 'type': 'while_statement', 'children': ['342', '356']}; {'id': '342', 'type': 'boolean_operator', 'children': ['343', '349'], 'value': 'and'}, {'id': '343', 'type': 'comparison_operator', 'children': ['344', '345'], 'value': '<'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '349', 'type': 'call', 'children': ['350', '355']}; {'id': '350', 'type': 'attribute', 'children': ['351', '354']}, {'id': '351', 'type': 'subscript', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'isspace'}, {'id': '355', 'type': 'argument_list', 'children': []}; {'id': '356', 'type': 'block', 'children': ['357']}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'augmented_assignment', 'children': ['359', '360'], 'value': '+='}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'i'} | def tokenize(self):
self.token_list = []
ps = self.parse_string.strip()
i = 0
last_token = None
while i < len(ps) and ps[i].isspace():
i += 1
while i < len(ps):
token = ''
if ps[i].isalpha():
while i < len(ps) and (ps[i].isalnum() or ps[i] == '_'):
token += ps[i]
i += 1
elif ps[i].isdigit():
while i < len(ps) and (ps[i].isdigit() or
ps[i] == '.' or
ps[i] == 'e' or
ps[i] == 'E' or
(ps[i] == '+' and (ps[i-1] == 'e' or ps[i-1] == 'E')) or
(ps[i] == '-' and (ps[i-1] == 'e' or ps[i-1] == 'E'))):
token += ps[i]
i += 1
elif ps[i] == '.':
if ps[i+1].isdigit():
while i < len(ps) and (ps[i].isdigit() or ps[i] == '.'):
token += ps[i]
i += 1
else:
while i < len(ps) and (ps[i].isalpha() or ps[i] == '.'):
token += ps[i]
i += 1
else:
token += ps[i]
i += 1
if token == '-' and \
(last_token == None or last_token == '(' or self.is_op(last_token)):
token = '~'
self.token_list += [token]
last_token = token
while i < len(ps) and ps[i].isspace():
i += 1 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_repo'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '7', '12', '17', '22', '39', '48', '63', '71', '83', '93', '97', '103', '115', '275']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'\\n [setup_repo]!'"}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'functools'}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '17', 'type': 'import_statement', 'children': ['18']}; {'id': '18', 'type': 'aliased_import', 'children': ['19', '21']}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'code_dpath'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'truepath'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_argval'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'--code-dir'"}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'~/code'"}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_code_dpath'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'unexpanduser'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'code_dpath'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'repo_fname'}, {'id': '51', 'type': 'parenthesized_expression', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_argval'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60']}, {'id': '57', 'type': 'tuple', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'--repo'"}, {'id': '59', 'type': 'string', 'children': [], 'value': "'--repo-name'"}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'code_dpath'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'repo_fname'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_argval'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'--modname'"}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'repo_fname'}, {'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': 'ut'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ensuredir'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '92', 'type': 'True', 'children': []}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_regencmd'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'python -m utool --tf setup_repo --repo={repo_fname} --codedir={_code_dpath} --modname={modname}'"}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'flake8_noqacmd'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'flake8'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "':noqa'"}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'regencmd'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_regencmd'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'dictionary_splat', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '114', 'type': 'argument_list', 'children': []}, {'id': '115', 'type': 'with_statement', 'children': ['116', '124']}; {'id': '116', 'type': 'with_clause', 'children': ['117']}, {'id': '117', 'type': 'with_item', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'ChdirContext'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '124', 'type': 'block', 'children': ['125', '131', '135', '151', '166', '181', '199', '214', '234', '257']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'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': 'force'}; {'id': '134', 'type': 'True', 'children': []}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'partial'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '145', '148']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ensure_text'}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'locals_'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '158']}, {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '157', 'type': 'string', 'children': [], 'value': "'todo.md'"}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'codeblock'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': "r'''\n * Add TODOS!\n '''"}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '173']}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'README.md'"}, {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'string', 'children': [], 'value': "r'''\n '''"}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '188', '191']}, {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'setup.py'"}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'chmod'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'+x'"}, {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'string', 'children': [], 'value': "r'''\n from __future__ import absolute_import, division, print_function, unicode_literals\n from setuptools import setup\n try:\n from utool import util_setup\n except ImportError:\n print('ERROR: setup requires utool')\n raise\n INSTALL_REQUIRES = [\n ]\n CLUTTER_PATTERNS = [\n ]\n if __name__ == '__main__':\n kwargs = util_setup.setuptools_setup(\n setup_fpath=__file__,\n name='{modname}',\n packages=util_setup.find_packages(),\n version=util_setup.parse_package_for_version('{modname}'),\n license=util_setup.read_license('LICENSE'),\n long_description=util_setup.parse_readme('README.md'),\n ext_modules=util_setup.find_ext_modules(),\n cmdclass=util_setup.get_cmdclass(),\n keywords='',\n install_requires=INSTALL_REQUIRES,\n clutter_patterns=CLUTTER_PATTERNS,\n classifiers=[],\n )\n setup(**kwargs)\n '''"}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '206']}, {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'.gitignore'"}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'codeblock'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'string', 'children': [], 'value': "r'''\n *.py[cod]\n *.so\n *.egg\n *.egg-info\n dist\n build\n eggs\n parts\n bin\n var\n sdist\n develop-eggs\n .installed.cfg\n lib\n lib64\n __pycache__\n pip-log.txt\n logs\n .coverage\n .tox\n nosetests.xml\n *.mo\n .mr.developer.cfg\n .project\n .pydevproject\n .DS_Store\n *.dump.txt\n *.sqlite3\n *.lprof\n *.prof\n *.flann\n *.npz\n _timeings.txt\n failed.txt\n *.orig\n _doc\n timeings.txt\n failed_doctests.txt\n '''"}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '226']}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'__init__.py'"}; {'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'codeblock'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'string', 'children': [], 'value': "r'''\n from __future__ import absolute_import, division, print_function, unicode_literals\n import sys\n __version__ = '0.0.0'\n IMPORT_TUPLES = [\n ]\n __DYNAMIC__ = '--nodyn' not in sys.argv\n DOELSE = False\n if __DYNAMIC__:\n from utool._internal import util_importer\n ignore_endswith = []\n import_execstr = util_importer.dynamic_import(\n __name__, IMPORT_TUPLES, ignore_endswith=ignore_endswith)\n exec(import_execstr)\n DOELSE = False\n else:\n DOELSE = True\n if DOELSE:\n pass\n '''"}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '246', '249']}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244', '245']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'__main__.py'"}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'chmod'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'+x'"}, {'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'string', 'children': [], 'value': "r'''\n from __future__ import absolute_import, division, print_function, unicode_literals\n def {modname}_main():\n ignore_prefix = []\n ignore_suffix = []\n import utool as ut\n ut.main_function_tester('{modname}', ignore_prefix, ignore_suffix)\n if __name__ == '__main__':\n print('Running {modname} main')\n {modname}_main()\n '''"}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': '_ensure_text'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '264', '267']}, {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '263', 'type': 'string', 'children': [], 'value': "'run_tests.py'"}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'chmod'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'+x'"}, {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'string', 'children': [], 'value': "r'''\n from __future__ import absolute_import, division, print_function\n import sys\n import utool as ut\n def run_tests():\n import sys\n ut.change_term_title('RUN {modname} TESTS')\n exclude_doctests_fnames = set([\n ])\n exclude_dirs = [\n '_broken', 'old', 'tests', 'timeits',\n '_scripts', '_timeits', '_doc', 'notebook',\n ]\n dpath_list = ['{modname}']\n doctest_modname_list = ut.find_doctestable_modnames(\n dpath_list, exclude_doctests_fnames, exclude_dirs)\n coverage = ut.get_argflag(('--coverage', '--cov',))\n if coverage:\n import coverage\n cov = coverage.Coverage(source=doctest_modname_list)\n cov.start()\n print('Starting coverage')\n exclude_lines = [\n 'pragma: no cover',\n 'def __repr__',\n 'if self.debug:',\n 'if settings.DEBUG',\n 'raise AssertionError',\n 'raise NotImplementedError',\n 'if 0:',\n 'if ut.VERBOSE',\n 'if _debug:',\n 'if __name__ == .__main__.:',\n 'print(.*)',\n ]\n for line in exclude_lines:\n cov.exclude(line)\n for modname in doctest_modname_list:\n exec('import ' + modname, globals())\n module_list = [sys.modules[name] for name in doctest_modname_list]\n nPass, nTotal, failed_cmd_list = ut.doctest_module_list(module_list)\n if coverage:\n print('Stoping coverage')\n cov.stop()\n print('Saving coverage')\n cov.save()\n print('Generating coverage html report')\n cov.html_report()\n if nPass != nTotal:\n return 1\n else:\n return 0\n if __name__ == '__main__':\n import multiprocessing\n multiprocessing.freeze_support()\n retcode = run_tests()\n sys.exit(retcode)\n '''"}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'ensuredir'}; {'id': '280', 'type': 'argument_list', 'children': ['281', '286']}, {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '283', 'type': 'argument_list', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'repo_dpath'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'verbose'} | def setup_repo():
r
print('\n [setup_repo]!')
from functools import partial
import utool as ut
code_dpath = ut.truepath(ut.get_argval('--code-dir', default='~/code'))
_code_dpath = ut.unexpanduser(code_dpath)
repo_fname = (ut.get_argval(('--repo', '--repo-name'), type_=str))
repo_dpath = join(code_dpath, repo_fname)
modname = ut.get_argval('--modname', default=repo_fname)
ut.ensuredir(repo_dpath, verbose=True)
_regencmd = 'python -m utool --tf setup_repo --repo={repo_fname} --codedir={_code_dpath} --modname={modname}'
flake8_noqacmd = 'flake8' + ':noqa'
regencmd = _regencmd.format(**locals())
with ut.ChdirContext(repo_dpath):
locals_ = locals()
force = True
_ensure_text = partial(ensure_text, repo_dpath='.', force=None, locals_=locals_)
_ensure_text(
fname='todo.md',
text=ut.codeblock(
r'''
* Add TODOS!
''')
)
_ensure_text(
fname='README.md',
text=ut.codeblock(
r'''
''')
)
_ensure_text(
fname='setup.py',
chmod='+x',
text=ut.codeblock(
r'''
from __future__ import absolute_import, division, print_function, unicode_literals
from setuptools import setup
try:
from utool import util_setup
except ImportError:
print('ERROR: setup requires utool')
raise
INSTALL_REQUIRES = [
]
CLUTTER_PATTERNS = [
]
if __name__ == '__main__':
kwargs = util_setup.setuptools_setup(
setup_fpath=__file__,
name='{modname}',
packages=util_setup.find_packages(),
version=util_setup.parse_package_for_version('{modname}'),
license=util_setup.read_license('LICENSE'),
long_description=util_setup.parse_readme('README.md'),
ext_modules=util_setup.find_ext_modules(),
cmdclass=util_setup.get_cmdclass(),
keywords='',
install_requires=INSTALL_REQUIRES,
clutter_patterns=CLUTTER_PATTERNS,
classifiers=[],
)
setup(**kwargs)
'''
)
)
_ensure_text(
fname='.gitignore',
text=ut.codeblock(
r'''
*.py[cod]
*.so
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__
pip-log.txt
logs
.coverage
.tox
nosetests.xml
*.mo
.mr.developer.cfg
.project
.pydevproject
.DS_Store
*.dump.txt
*.sqlite3
*.lprof
*.prof
*.flann
*.npz
_timeings.txt
failed.txt
*.orig
_doc
timeings.txt
failed_doctests.txt
'''
)
)
_ensure_text(
fname=join(repo_dpath, modname, '__init__.py'),
text=ut.codeblock(
r'''
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
__version__ = '0.0.0'
IMPORT_TUPLES = [
]
__DYNAMIC__ = '--nodyn' not in sys.argv
DOELSE = False
if __DYNAMIC__:
from utool._internal import util_importer
ignore_endswith = []
import_execstr = util_importer.dynamic_import(
__name__, IMPORT_TUPLES, ignore_endswith=ignore_endswith)
exec(import_execstr)
DOELSE = False
else:
DOELSE = True
if DOELSE:
pass
'''
)
)
_ensure_text(
fname=join(repo_dpath, modname, '__main__.py'),
chmod='+x',
text=ut.codeblock(
r'''
from __future__ import absolute_import, division, print_function, unicode_literals
def {modname}_main():
ignore_prefix = []
ignore_suffix = []
import utool as ut
ut.main_function_tester('{modname}', ignore_prefix, ignore_suffix)
if __name__ == '__main__':
print('Running {modname} main')
{modname}_main()
'''
)
)
_ensure_text(
fname='run_tests.py',
chmod='+x',
text=ut.codeblock(
r'''
from __future__ import absolute_import, division, print_function
import sys
import utool as ut
def run_tests():
import sys
ut.change_term_title('RUN {modname} TESTS')
exclude_doctests_fnames = set([
])
exclude_dirs = [
'_broken', 'old', 'tests', 'timeits',
'_scripts', '_timeits', '_doc', 'notebook',
]
dpath_list = ['{modname}']
doctest_modname_list = ut.find_doctestable_modnames(
dpath_list, exclude_doctests_fnames, exclude_dirs)
coverage = ut.get_argflag(('--coverage', '--cov',))
if coverage:
import coverage
cov = coverage.Coverage(source=doctest_modname_list)
cov.start()
print('Starting coverage')
exclude_lines = [
'pragma: no cover',
'def __repr__',
'if self.debug:',
'if settings.DEBUG',
'raise AssertionError',
'raise NotImplementedError',
'if 0:',
'if ut.VERBOSE',
'if _debug:',
'if __name__ == .__main__.:',
'print(.*)',
]
for line in exclude_lines:
cov.exclude(line)
for modname in doctest_modname_list:
exec('import ' + modname, globals())
module_list = [sys.modules[name] for name in doctest_modname_list]
nPass, nTotal, failed_cmd_list = ut.doctest_module_list(module_list)
if coverage:
print('Stoping coverage')
cov.stop()
print('Saving coverage')
cov.save()
print('Generating coverage html report')
cov.html_report()
if nPass != nTotal:
return 1
else:
return 0
if __name__ == '__main__':
import multiprocessing
multiprocessing.freeze_support()
retcode = run_tests()
sys.exit(retcode)
'''
)
)
ut.ensuredir(join(repo_dpath, modname), verbose=True) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args_gen'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ordered'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'force_serial'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'use_pool'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'progkw'}, {'id': '29', 'type': 'dictionary', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'nTasks'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37', '39', '48', '57', '88', '101', '108', '123', '138', '147', '159', '173']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '42', 'type': 'None', 'children': []}, {'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': 'verbose'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'nTasks'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'try_statement', 'children': ['63', '71']}, {'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': 'ntasks'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'args_gen'}, {'id': '71', 'type': 'except_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '73', 'type': 'block', 'children': ['74', '81']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'args_gen'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'args_gen'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'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': 'args_gen'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '96']}, {'id': '89', 'type': 'boolean_operator', 'children': ['90', '93'], 'value': 'or'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '<'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '__MIN_PARALLEL_TASKS__'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'force_serial'}; {'id': '100', 'type': 'True', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '__FORCE_SERIAL__'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'force_serial'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '__FORCE_SERIAL__'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'block', 'children': ['113', '121']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'[ut.generate2] submitted 0 tasks'"}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '127']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '126', 'type': 'None', 'children': []}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'get_default_numprocs'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'if_statement', 'children': ['139', '142']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '=='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'force_serial'}; {'id': '146', 'type': 'True', 'children': []}, {'id': '147', 'type': 'if_statement', 'children': ['148', '151']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}; {'id': '150', 'type': 'None', 'children': []}, {'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': 'kw_gen'}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '158'], 'value': '*'}; {'id': '156', 'type': 'list', 'children': ['157'], 'value': '[{}]'}, {'id': '157', 'type': 'dictionary', 'children': []}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '165']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '172'], 'value': '*'}; {'id': '170', 'type': 'list', 'children': ['171'], 'value': '[kw_gen]'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '173', 'type': 'if_statement', 'children': ['174', '175', '197']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'force_serial'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'for_statement', 'children': ['177', '178', '193']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_generate_serial2'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182', '183', '184', '187', '190']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'args_gen'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'progkw'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'progkw'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'yield', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199', '229', '285']}, {'id': '199', 'type': 'if_statement', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '201', 'type': 'block', 'children': ['202', '209', '213']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'gentype'}, {'id': '205', 'type': 'conditional_expression', 'children': ['206', '207', '208'], 'value': 'if'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'mp'"}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'use_pool'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'futures'"}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'fmtstr'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'[generate2] executing {} {} tasks using {} {} procs'"}, {'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': 'identifier', 'children': [], 'value': 'fmtstr'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223', '227', '228']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ntasks'}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'gentype'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '233']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': '>'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'block', 'children': ['234', '244', '262', '269']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '%'}; {'id': '238', 'type': 'string', 'children': [], 'value': "'(pargen) %s: '"}, {'id': '239', 'type': 'tuple', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'progkw_'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '253', '256', '259']}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '252', 'type': 'None', 'children': []}, {'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'bs'}, {'id': '255', 'type': 'True', 'children': []}; {'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'adjust'}; {'id': '258', 'type': 'False', 'children': []}, {'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'freq_est'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'absolute'"}; {'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': 'progkw_'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'progkw'}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'progpart'}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'util_progress'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ProgPartial'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '280', '283']}, {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '283', 'type': 'dictionary_splat', 'children': ['284']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'progkw_'}, {'id': '285', 'type': 'if_statement', 'children': ['286', '287', '399']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'use_pool'}, {'id': '287', 'type': 'block', 'children': ['288', '314']}; {'id': '288', 'type': 'if_statement', 'children': ['289', '292']}, {'id': '289', 'type': 'comparison_operator', 'children': ['290', '291'], 'value': 'is'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '291', 'type': 'None', 'children': []}; {'id': '292', 'type': 'block', 'children': ['293']}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'chunksize'}; {'id': '296', 'type': 'call', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '298', 'type': 'argument_list', 'children': ['299', '304']}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '301', 'type': 'argument_list', 'children': ['302', '303']}; {'id': '302', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308']}, {'id': '307', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '//'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'ntasks'}; {'id': '310', 'type': 'parenthesized_expression', 'children': ['311']}, {'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '**'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '314', 'type': 'try_statement', 'children': ['315', '385']}, {'id': '315', 'type': 'block', 'children': ['316', '325', '342', '357', '366', '378']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'Pool'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '325', 'type': 'if_statement', 'children': ['326', '327', '334']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'pmap_func'}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '334', 'type': 'else_clause', 'children': ['335']}, {'id': '335', 'type': 'block', 'children': ['336']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'pmap_func'}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'imap_unordered'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'assignment', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'wrapped_arg_gen'}, {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '347', 'type': 'argument_list', 'children': ['348', '355', '356']}; {'id': '348', 'type': 'binary_operator', 'children': ['349', '351'], 'value': '*'}, {'id': '349', 'type': 'list', 'children': ['350'], 'value': '[func]'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '351', 'type': 'call', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'args_gen'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'args_gen'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'res_gen'}; {'id': '360', 'type': 'call', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'pmap_func'}; {'id': '362', 'type': 'argument_list', 'children': ['363', '364', '365']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': '_kw_wrap_worker'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'wrapped_arg_gen'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'chunksize'}; {'id': '366', 'type': 'if_statement', 'children': ['367', '370']}, {'id': '367', 'type': 'comparison_operator', 'children': ['368', '369'], 'value': '>'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '369', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '370', 'type': 'block', 'children': ['371']}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'res_gen'}; {'id': '374', 'type': 'call', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'progpart'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'res_gen'}; {'id': '378', 'type': 'for_statement', 'children': ['379', '380', '381']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'res_gen'}, {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'yield', 'children': ['384']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '385', 'type': 'finally_clause', 'children': ['386']}; {'id': '386', 'type': 'block', 'children': ['387', '393']}, {'id': '387', 'type': 'expression_statement', 'children': ['388']}; {'id': '388', 'type': 'call', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '392', 'type': 'argument_list', 'children': []}, {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'call', 'children': ['395', '398']}, {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '398', 'type': 'argument_list', 'children': []}, {'id': '399', 'type': 'else_clause', 'children': ['400']}; {'id': '400', 'type': 'block', 'children': ['401', '410']}, {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'assignment', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'executor'}; {'id': '404', 'type': 'call', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'futures'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'ProcessPoolExecutor'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '410', 'type': 'try_statement', 'children': ['411', '475']}, {'id': '411', 'type': 'block', 'children': ['412', '435', '439', '452', '464']}; {'id': '412', 'type': 'expression_statement', 'children': ['413']}, {'id': '413', 'type': 'assignment', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'fs_list'}, {'id': '415', 'type': 'list_comprehension', 'children': ['416', '426']}; {'id': '416', 'type': 'call', 'children': ['417', '420']}, {'id': '417', 'type': 'attribute', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'executor'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'submit'}; {'id': '420', 'type': 'argument_list', 'children': ['421', '422', '424']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '422', 'type': 'list_splat', 'children': ['423']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '424', 'type': 'dictionary_splat', 'children': ['425']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '426', 'type': 'for_in_clause', 'children': ['427', '430']}, {'id': '427', 'type': 'pattern_list', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '430', 'type': 'call', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '432', 'type': 'argument_list', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'args_gen'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'kw_gen'}, {'id': '435', 'type': 'expression_statement', 'children': ['436']}; {'id': '436', 'type': 'assignment', 'children': ['437', '438']}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'fs_list'}, {'id': '439', 'type': 'if_statement', 'children': ['440', '442']}; {'id': '440', 'type': 'not_operator', 'children': ['441']}, {'id': '441', 'type': 'identifier', 'children': [], 'value': 'ordered'}; {'id': '442', 'type': 'block', 'children': ['443']}, {'id': '443', 'type': 'expression_statement', 'children': ['444']}; {'id': '444', 'type': 'assignment', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}; {'id': '446', 'type': 'call', 'children': ['447', '450']}, {'id': '447', 'type': 'attribute', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'futures'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'as_completed'}; {'id': '450', 'type': 'argument_list', 'children': ['451']}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}; {'id': '452', 'type': 'if_statement', 'children': ['453', '456']}, {'id': '453', 'type': 'comparison_operator', 'children': ['454', '455'], 'value': '>'}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '455', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '456', 'type': 'block', 'children': ['457']}, {'id': '457', 'type': 'expression_statement', 'children': ['458']}; {'id': '458', 'type': 'assignment', 'children': ['459', '460']}, {'id': '459', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}; {'id': '460', 'type': 'call', 'children': ['461', '462']}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'progpart'}; {'id': '462', 'type': 'argument_list', 'children': ['463']}, {'id': '463', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}; {'id': '464', 'type': 'for_statement', 'children': ['465', '466', '467']}, {'id': '465', 'type': 'identifier', 'children': [], 'value': 'fs'}; {'id': '466', 'type': 'identifier', 'children': [], 'value': 'fs_gen'}, {'id': '467', 'type': 'block', 'children': ['468']}; {'id': '468', 'type': 'expression_statement', 'children': ['469']}, {'id': '469', 'type': 'yield', 'children': ['470']}; {'id': '470', 'type': 'call', 'children': ['471', '474']}, {'id': '471', 'type': 'attribute', 'children': ['472', '473']}; {'id': '472', 'type': 'identifier', 'children': [], 'value': 'fs'}, {'id': '473', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '474', 'type': 'argument_list', 'children': []}, {'id': '475', 'type': 'finally_clause', 'children': ['476']}; {'id': '476', 'type': 'block', 'children': ['477']}, {'id': '477', 'type': 'expression_statement', 'children': ['478']}; {'id': '478', 'type': 'call', 'children': ['479', '482']}, {'id': '479', 'type': 'attribute', 'children': ['480', '481']}; {'id': '480', 'type': 'identifier', 'children': [], 'value': 'executor'}, {'id': '481', 'type': 'identifier', 'children': [], 'value': 'shutdown'}; {'id': '482', 'type': 'argument_list', 'children': ['483']}, {'id': '483', 'type': 'keyword_argument', 'children': ['484', '485']}; {'id': '484', 'type': 'identifier', 'children': [], 'value': 'wait'}, {'id': '485', 'type': 'True', 'children': []} | def generate2(func, args_gen, kw_gen=None, ntasks=None, ordered=True,
force_serial=False, use_pool=False, chunksize=None, nprocs=None,
progkw={}, nTasks=None, verbose=None):
r
if verbose is None:
verbose = 2
if ntasks is None:
ntasks = nTasks
if ntasks is None:
try:
ntasks = len(args_gen)
except TypeError:
args_gen = list(args_gen)
ntasks = len(args_gen)
if ntasks == 1 or ntasks < __MIN_PARALLEL_TASKS__:
force_serial = True
if __FORCE_SERIAL__:
force_serial = __FORCE_SERIAL__
if ntasks == 0:
if verbose:
print('[ut.generate2] submitted 0 tasks')
raise StopIteration
if nprocs is None:
nprocs = min(ntasks, get_default_numprocs())
if nprocs == 1:
force_serial = True
if kw_gen is None:
kw_gen = [{}] * ntasks
if isinstance(kw_gen, dict):
kw_gen = [kw_gen] * ntasks
if force_serial:
for result in _generate_serial2(func, args_gen, kw_gen,
ntasks=ntasks, progkw=progkw,
verbose=verbose):
yield result
else:
if verbose:
gentype = 'mp' if use_pool else 'futures'
fmtstr = '[generate2] executing {} {} tasks using {} {} procs'
print(fmtstr.format(ntasks, get_funcname(func), nprocs, gentype))
if verbose > 1:
lbl = '(pargen) %s: ' % (get_funcname(func),)
progkw_ = dict(freq=None, bs=True, adjust=False, freq_est='absolute')
progkw_.update(progkw)
progpart = util_progress.ProgPartial(length=ntasks, lbl=lbl, **progkw_)
if use_pool:
if chunksize is None:
chunksize = max(min(4, ntasks), min(8, ntasks // (nprocs ** 2)))
try:
pool = multiprocessing.Pool(nprocs)
if ordered:
pmap_func = pool.imap
else:
pmap_func = pool.imap_unordered
wrapped_arg_gen = zip([func] * len(args_gen), args_gen, kw_gen)
res_gen = pmap_func(_kw_wrap_worker, wrapped_arg_gen,
chunksize)
if verbose > 1:
res_gen = progpart(res_gen)
for res in res_gen:
yield res
finally:
pool.close()
pool.join()
else:
executor = futures.ProcessPoolExecutor(nprocs)
try:
fs_list = [executor.submit(func, *a, **k)
for a, k in zip(args_gen, kw_gen)]
fs_gen = fs_list
if not ordered:
fs_gen = futures.as_completed(fs_gen)
if verbose > 1:
fs_gen = progpart(fs_gen)
for fs in fs_gen:
yield fs.result()
finally:
executor.shutdown(wait=True) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'buffered_generator'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source_gen'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'buffer_size'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'use_multiprocessing'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '24', '94', '105', '109', '127', '133', '139']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '<'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'buffer_size'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '2'}; {'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': '"Minimal buffer_ size is 2!"'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26', '78']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'use_multiprocessing'}; {'id': '26', 'type': 'block', 'children': ['27', '32', '68', '74']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'WARNING seems to freeze if passed in a generator'"}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34', '60']}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '54']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Pool'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '48', '51']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'processes'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_default_numprocs'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'initializer'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'init_worker'}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'maxtasksperchild'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Process'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Process'}; {'id': '60', 'type': 'else_clause', 'children': ['61']}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'Process'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Process'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_Queue'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_buffered_generation_process'}; {'id': '78', 'type': 'else_clause', 'children': ['79']}, {'id': '79', 'type': 'block', 'children': ['80', '86', '90']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_Queue'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Process'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'KillableThread'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_buffered_generation_thread'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'buffer_'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_Queue'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'maxsize'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '-'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'buffer_size'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sentinal'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'Process'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '118']}, {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '120', 'type': 'tuple', 'children': ['121', '125', '126']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'source_gen'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'buffer_'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sentinal'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '132', 'type': 'True', 'children': []}, {'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': 'process'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'while_statement', 'children': ['140', '141']}; {'id': '140', 'type': 'True', 'children': []}, {'id': '141', 'type': 'block', 'children': ['142', '150', '157']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'buffer_'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '154']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sentinal'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'raise_statement', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'yield', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'output'} | def buffered_generator(source_gen, buffer_size=2, use_multiprocessing=False):
r
if buffer_size < 2:
raise RuntimeError("Minimal buffer_ size is 2!")
if use_multiprocessing:
print('WARNING seems to freeze if passed in a generator')
if False:
pool = multiprocessing.Pool(processes=get_default_numprocs(),
initializer=init_worker,
maxtasksperchild=None)
Process = pool.Process
else:
Process = multiprocessing.Process
_Queue = multiprocessing.Queue
target = _buffered_generation_process
else:
_Queue = queue.Queue
Process = KillableThread
target = _buffered_generation_thread
buffer_ = _Queue(maxsize=buffer_size - 1)
sentinal = StopIteration
process = Process(
target=target,
args=(iter(source_gen), buffer_, sentinal)
)
process.daemon = True
process.start()
while True:
output = buffer_.get()
if output is sentinal:
raise StopIteration
yield output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_window_ids'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'winid_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'mru'"}; {'id': '8', 'type': 'block', 'children': ['9', '14', '23', '33']}, {'id': '9', 'type': 'import_statement', 'children': ['10']}; {'id': '10', 'type': 'aliased_import', 'children': ['11', '13']}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'winid_order'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'XCtrl'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted_window_ids'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted_win_ids'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isect'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'winid_order'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'winid_list'}, {'id': '33', 'type': 'return_statement', 'children': ['34']} | def sort_window_ids(winid_list, order='mru'):
import utool as ut
winid_order = XCtrl.sorted_window_ids(order)
sorted_win_ids = ut.isect(winid_order, winid_list)
return sorted_win_ids |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__infer_setup_kwargs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '23', '41', '59', '79']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '10', 'type': 'subscript', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'packages'"}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'packages'}, {'id': '27', 'type': 'block', 'children': ['28', '35']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'packages'"}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'packages'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '45', 'type': 'block', 'children': ['46', '53']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'parse_package_for_version'}, {'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', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'not'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'license'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'try_statement', 'children': ['65', '75']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'license'"}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'read_license'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'LICENSE'"}, {'id': '75', 'type': 'except_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'pass_statement', 'children': []}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'not'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'long_description'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'long_description'"}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'parse_readme'}, {'id': '91', 'type': 'argument_list', 'children': []} | def __infer_setup_kwargs(module, kwargs):
name = kwargs['name']
packages = kwargs.get('packages', [])
if name not in packages:
packages.append(name)
kwargs['packages'] = packages
if 'version' not in kwargs:
version = parse_package_for_version(name)
kwargs['version'] = version
if 'license' not in kwargs:
try:
kwargs['license'] = read_license('LICENSE')
except IOError:
pass
if 'long_description' not in kwargs:
kwargs['long_description'] = parse_readme() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'on_exception_report_input'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func_'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '376']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': '_closure_onexceptreport'}; {'id': '16', 'type': 'parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '18', 'type': 'block', 'children': ['19', '28', '366', '374']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '25']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '23'], 'value': 'and'}, {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ONEX_REPORT_INPUT'}, {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '28', 'type': 'decorated_definition', 'children': ['29', '36']}, {'id': '29', 'type': 'decorator', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ignores_exc_tb'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'outer_wrapper'}, {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'function_definition', 'children': ['37', '38', '43']}, {'id': '37', 'type': 'function_name', 'children': [], 'value': 'wrp_onexceptreport'}; {'id': '38', 'type': 'parameters', 'children': ['39', '41']}, {'id': '39', 'type': 'list_splat_pattern', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '41', 'type': 'dictionary_splat_pattern', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'try_statement', 'children': ['45', '54']}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '52']}; {'id': '50', 'type': 'list_splat', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '52', 'type': 'dictionary_splat', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '54', 'type': 'except_clause', 'children': ['55', '59']}, {'id': '55', 'type': 'as_pattern', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '57', 'type': 'as_pattern_target', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '59', 'type': 'block', 'children': ['60', '65', '70', '268', '292', '321', '336', '345', '354', '365']}; {'id': '60', 'type': 'import_from_statement', 'children': ['61', '63']}, {'id': '61', 'type': 'dotted_name', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '63', 'type': 'dotted_name', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': "'ERROR occured! Reporting input to function'"}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75', '80', '85', '90', '99', '109', '119', '132', '141', '151', '166', '182', '199', '217', '227', '249', '267']}, {'id': '75', 'type': 'import_from_statement', 'children': ['76', '78']}; {'id': '76', 'type': 'dotted_name', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '78', 'type': 'dotted_name', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}; {'id': '80', 'type': 'import_from_statement', 'children': ['81', '83']}, {'id': '81', 'type': 'dotted_name', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '83', 'type': 'dotted_name', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'util_list'}, {'id': '85', 'type': 'import_from_statement', 'children': ['86', '88']}; {'id': '86', 'type': 'dotted_name', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '88', 'type': 'dotted_name', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'util_dict'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_func_argspec'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'in_kwargs_flags'}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '106']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwarg_keys'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'util_list'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'compress'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'in_kwargs_flags'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwarg_vals'}; {'id': '122', 'type': 'list_comprehension', 'children': ['123', '129']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'kwarg_keys'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'util_list'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'not_list'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'in_kwargs_flags'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'arg_keys'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'util_list'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'compress'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'arg_idxs'}; {'id': '154', 'type': 'list_comprehension', 'children': ['155', '163']}, {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '163', 'type': 'for_in_clause', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'arg_keys'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'num_nodefault'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '176'], 'value': '-'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'default_vals'}, {'id': '185', 'type': 'parenthesized_expression', 'children': ['186']}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '193'], 'value': '+'}, {'id': '187', 'type': 'parenthesized_expression', 'children': ['188']}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '191'], 'value': '*'}, {'id': '189', 'type': 'list', 'children': ['190'], 'value': '[None]'}; {'id': '190', 'type': 'None', 'children': []}, {'id': '191', 'type': 'parenthesized_expression', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'num_nodefault'}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '207'], 'value': '+'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'default_vals'}, {'id': '209', 'type': 'slice', 'children': ['210', '216']}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '215'], 'value': '+'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'colon', 'children': []}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'arg_vals'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'util_list'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'take'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'arg_idxs'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'requested_dict'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'util_list'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'list', 'children': ['239', '244'], 'value': '[zip(kwarg_keys, kwarg_vals), zip(arg_keys, arg_vals)]'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'kwarg_keys'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'kwarg_vals'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'arg_keys'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'arg_vals'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '+'}; {'id': '254', 'type': 'string', 'children': [], 'value': "'input dict = '"}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'repr4'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'util_dict'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'dict_subset'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'requested_dict'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '267', 'type': 'pass_statement', 'children': []}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'arg_strs'}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'list_comprehension', 'children': ['277', '289']}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'truncate_str'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '289', 'type': 'for_in_clause', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'kwarg_strs'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'list_comprehension', 'children': ['301', '311']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'truncate_str'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '%'}, {'id': '307', 'type': 'string', 'children': [], 'value': "'%s=%r'"}; {'id': '308', 'type': 'tuple', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '311', 'type': 'for_in_clause', 'children': ['312', '315']}; {'id': '312', 'type': 'pattern_list', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '324', 'type': 'parenthesized_expression', 'children': ['325']}, {'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '%'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'\\nERROR: funcname=%r,\\n * args=%s,\\n * kwargs=%r\\n'"}, {'id': '327', 'type': 'tuple', 'children': ['328', '334', '335']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'arg_strs'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'kwarg_strs'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'augmented_assignment', 'children': ['338', '339'], 'value': '+='}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '339', 'type': 'binary_operator', 'children': ['340', '341'], 'value': '%'}; {'id': '340', 'type': 'string', 'children': [], 'value': "' * len(args) = %r\\n'"}, {'id': '341', 'type': 'call', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'augmented_assignment', 'children': ['347', '348'], 'value': '+='}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '348', 'type': 'binary_operator', 'children': ['349', '350'], 'value': '%'}, {'id': '349', 'type': 'string', 'children': [], 'value': "' * len(kwargs) = %r\\n'"}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'printex'}, {'id': '359', 'type': 'argument_list', 'children': ['360', '361', '362']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '362', 'type': 'keyword_argument', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'pad_stdout'}; {'id': '364', 'type': 'True', 'children': []}, {'id': '365', 'type': 'raise_statement', 'children': []}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'assignment', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'wrp_onexceptreport'}, {'id': '369', 'type': 'call', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'preserve_sig'}, {'id': '371', 'type': 'argument_list', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'wrp_onexceptreport'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '374', 'type': 'return_statement', 'children': ['375']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'wrp_onexceptreport'}; {'id': '376', 'type': 'if_statement', 'children': ['377', '380', '383']}, {'id': '377', 'type': 'comparison_operator', 'children': ['378', '379'], 'value': 'is'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'func_'}, {'id': '379', 'type': 'None', 'children': []}; {'id': '380', 'type': 'block', 'children': ['381']}, {'id': '381', 'type': 'return_statement', 'children': ['382']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': '_closure_onexceptreport'}, {'id': '383', 'type': 'else_clause', 'children': ['384']}; {'id': '384', 'type': 'block', 'children': ['385']}, {'id': '385', 'type': 'return_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': '_closure_onexceptreport'}; {'id': '388', 'type': 'argument_list', 'children': ['389']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'func_'} | def on_exception_report_input(func_=None, force=False, keys=None):
def _closure_onexceptreport(func):
if not ONEX_REPORT_INPUT and not force:
return func
@ignores_exc_tb(outer_wrapper=False)
def wrp_onexceptreport(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as ex:
from utool import util_str
print('ERROR occured! Reporting input to function')
if keys is not None:
from utool import util_inspect
from utool import util_list
from utool import util_dict
argspec = util_inspect.get_func_argspec(func)
in_kwargs_flags = [key in kwargs for key in keys]
kwarg_keys = util_list.compress(keys, in_kwargs_flags)
kwarg_vals = [kwargs.get(key) for key in kwarg_keys]
flags = util_list.not_list(in_kwargs_flags)
arg_keys = util_list.compress(keys, flags)
arg_idxs = [argspec.args.index(key) for key in arg_keys]
num_nodefault = len(argspec.args) - len(argspec.defaults)
default_vals = (([None] * (num_nodefault)) +
list(argspec.defaults))
args_ = list(args) + default_vals[len(args) + 1:]
arg_vals = util_list.take(args_, arg_idxs)
requested_dict = dict(util_list.flatten(
[zip(kwarg_keys, kwarg_vals), zip(arg_keys, arg_vals)]))
print('input dict = ' + util_str.repr4(
util_dict.dict_subset(requested_dict, keys)))
pass
arg_strs = ', '.join([repr(util_str.truncate_str(str(arg)))
for arg in args])
kwarg_strs = ', '.join([
util_str.truncate_str('%s=%r' % (key, val))
for key, val in six.iteritems(kwargs)])
msg = ('\nERROR: funcname=%r,\n * args=%s,\n * kwargs=%r\n' % (
meta_util_six.get_funcname(func), arg_strs, kwarg_strs))
msg += ' * len(args) = %r\n' % len(args)
msg += ' * len(kwargs) = %r\n' % len(kwargs)
util_dbg.printex(ex, msg, pad_stdout=True)
raise
wrp_onexceptreport = preserve_sig(wrp_onexceptreport, func)
return wrp_onexceptreport
if func_ is None:
return _closure_onexceptreport
else:
return _closure_onexceptreport(func_) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'accepts_scalar_input'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'block', 'children': ['6', '66', '74']}; {'id': '6', 'type': 'decorated_definition', 'children': ['7', '14']}, {'id': '7', 'type': 'decorator', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ignores_exc_tb'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'outer_wrapper'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '23']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': 'wrp_asi'}; {'id': '16', 'type': 'parameters', 'children': ['17', '18', '19', '21']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'input_'}, {'id': '19', 'type': 'list_splat_pattern', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '31', '42']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'util_iter'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isiterable'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'input_'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38', '40']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'input_'}; {'id': '38', 'type': 'list_splat', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '40', 'type': 'dictionary_splat', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'id': '43', 'type': 'block', 'children': ['44', '57']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '53', '55']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'list', 'children': ['52'], 'value': '[input_]'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'input_'}, {'id': '53', 'type': 'list_splat', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '55', 'type': 'dictionary_splat', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'wrp_asi'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'preserve_sig'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'wrp_asi'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'wrp_asi'} | def accepts_scalar_input(func):
@ignores_exc_tb(outer_wrapper=False)
def wrp_asi(self, input_, *args, **kwargs):
if util_iter.isiterable(input_):
return func(self, input_, *args, **kwargs)
else:
ret = func(self, [input_], *args, **kwargs)
if ret is not None:
return ret[0]
wrp_asi = preserve_sig(wrp_asi, func)
return wrp_asi |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'preserve_sig'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'wrapper'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '21', '26', '33', '42', '51', '60', '71', '80', '84', '90', '96', '102', '108', '127', '146', '160', '302', '306', '329', '349', '357', '363']}; {'id': '10', 'type': 'import_from_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'dotted_name', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_internal'}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}; {'id': '16', 'type': 'import_from_statement', 'children': ['17', '19']}, {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '21', 'type': 'import_from_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'wrapper'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'orig_func'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_funcdoc'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}, {'id': '45', 'type': 'conditional_expression', 'children': ['46', '47', '50'], 'value': 'if'}; {'id': '46', 'type': 'string', 'children': [], 'value': "''"}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'orig_argspec'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_func_argspec'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'wrap_name'}, {'id': '63', 'type': 'attribute', 'children': ['64', '70']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get_funccode'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'co_name'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'orig_name'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_utinfo'}, {'id': '83', 'type': 'dictionary', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'orig_func'"}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'wrap_name'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'wrap_name'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '101']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'orig_name'"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'orig_name'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'orig_argspec'"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'orig_argspec'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '114']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'wrapper'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'_utinfo'"}; {'id': '114', 'type': 'block', 'children': ['115', '121']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'parent_wrapper_utinfo'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_utinfo'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_utinfo'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'parent_wrapper_utinfo'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'parent_wrapper_utinfo'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '133']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'_utinfo'"}, {'id': '133', 'type': 'block', 'children': ['134', '140']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'parent_orig_utinfo'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'orig_func'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'parent_orig_utinfo'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'parent_orig_utinfo'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'building_docs'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '159'], 'value': '=='}; {'id': '150', 'type': 'call', 'children': ['151', '156']}, {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'UTOOL_AUTOGEN_SPHINX_RUNNING'"}; {'id': '158', 'type': 'string', 'children': [], 'value': "'OFF'"}, {'id': '159', 'type': 'string', 'children': [], 'value': "'ON'"}; {'id': '160', 'type': 'if_statement', 'children': ['161', '166', '290']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'or'}; {'id': '162', 'type': 'boolean_operator', 'children': ['163', '164'], 'value': 'or'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'SIG_PRESERVE'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'building_docs'}; {'id': '166', 'type': 'block', 'children': ['167', '171', '178', '182', '191', '199', '209', '224', '239', '254', '263', '272', '284']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'src_fmt'}; {'id': '170', 'type': 'string', 'children': [], 'value': "r'''\n def _wrp_preserve{defsig}:\n try:\n return wrapper{callsig}\n except Exception as ex:\n import utool as ut\n msg = ('Failure in signature preserving wrapper:\\n')\n ut.printex(ex, msg)\n raise\n '''"}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'globals_'}; {'id': '174', 'type': 'dictionary', 'children': ['175']}, {'id': '175', 'type': 'pair', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': "'wrapper'"}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'locals_'}, {'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': 'argspec'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'getargspec'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'orig_func'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '198']}, {'id': '193', 'type': 'tuple_pattern', 'children': ['194', '195', '196', '197']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'varkw'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'defsig'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'formatargspec'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'list_splat', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'callsig'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'formatargspec'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'list_splat', 'children': ['218']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '220', 'type': 'slice', 'children': ['221', '222', '223']}, {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'colon', 'children': []}, {'id': '223', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'src_fmtdict'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '233', '236']}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'defsig'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'defsig'}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'callsig'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'callsig'}; {'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '242', 'type': 'call', 'children': ['243', '251']}, {'id': '243', 'type': 'attribute', 'children': ['244', '250']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'textwrap'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'dedent'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'src_fmt'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'dictionary_splat', 'children': ['253']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'src_fmtdict'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261', '262']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'src'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'<string>'"}; {'id': '262', 'type': 'string', 'children': [], 'value': "'exec'"}, {'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': 'six'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'exec_'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'globals_'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': '_wrp_preserve'}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'update_wrapper'}, {'id': '279', 'type': 'argument_list', 'children': ['280', '283']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'locals_'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'_wrp_preserve'"}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '289']}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'src'"}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}, {'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': '_wrp_preserve'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'update_wrapper'}, {'id': '299', 'type': 'argument_list', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'wrapper'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'DEBUG_WRAPPED_DOCSTRING'}, {'id': '305', 'type': 'False', 'children': []}; {'id': '306', 'type': 'if_statement', 'children': ['307', '308', '318']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'DEBUG_WRAPPED_DOCSTRING'}; {'id': '308', 'type': 'block', 'children': ['309']}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'new_docstr_fmtstr'}; {'id': '312', 'type': 'call', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'codeblock'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'string', 'children': [], 'value': "'''\n Wrapped function {wrap_name}({orig_name})\n orig_argspec = {orig_argspec}\n orig_docstr = {orig_docstr}\n '''"}; {'id': '318', 'type': 'else_clause', 'children': ['319']}, {'id': '319', 'type': 'block', 'children': ['320']}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'new_docstr_fmtstr'}, {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'string', 'children': [], 'value': "'''\n {orig_docstr}\n '''"}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'new_docstr'}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'new_docstr_fmtstr'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '340', '343', '346']}, {'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'wrap_name'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'wrap_name'}; {'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'orig_name'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'orig_name'}, {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'orig_docstr'}; {'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'orig_argspec'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'orig_argspec'}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'set_funcdoc'}; {'id': '354', 'type': 'argument_list', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': '_wrp_preserve'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'new_docstr'}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '362']}, {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': '_wrp_preserve'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': '_utinfo'}, {'id': '363', 'type': 'return_statement', 'children': ['364']} | def preserve_sig(wrapper, orig_func, force=False):
from utool._internal import meta_util_six
from utool import util_str
from utool import util_inspect
if wrapper is orig_func:
return orig_func
orig_docstr = meta_util_six.get_funcdoc(orig_func)
orig_docstr = '' if orig_docstr is None else orig_docstr
orig_argspec = util_inspect.get_func_argspec(orig_func)
wrap_name = meta_util_six.get_funccode(wrapper).co_name
orig_name = meta_util_six.get_funcname(orig_func)
_utinfo = {}
_utinfo['orig_func'] = orig_func
_utinfo['wrap_name'] = wrap_name
_utinfo['orig_name'] = orig_name
_utinfo['orig_argspec'] = orig_argspec
if hasattr(wrapper, '_utinfo'):
parent_wrapper_utinfo = wrapper._utinfo
_utinfo['parent_wrapper_utinfo'] = parent_wrapper_utinfo
if hasattr(orig_func, '_utinfo'):
parent_orig_utinfo = orig_func._utinfo
_utinfo['parent_orig_utinfo'] = parent_orig_utinfo
building_docs = os.environ.get('UTOOL_AUTOGEN_SPHINX_RUNNING', 'OFF') == 'ON'
if force or SIG_PRESERVE or building_docs:
src_fmt = r'''
def _wrp_preserve{defsig}:
try:
return wrapper{callsig}
except Exception as ex:
import utool as ut
msg = ('Failure in signature preserving wrapper:\n')
ut.printex(ex, msg)
raise
'''
globals_ = {'wrapper': wrapper}
locals_ = {}
argspec = inspect.getargspec(orig_func)
(args, varargs, varkw, defaults) = argspec
defsig = inspect.formatargspec(*argspec)
callsig = inspect.formatargspec(*argspec[0:3])
src_fmtdict = dict(defsig=defsig, callsig=callsig, orig_docstr=orig_docstr)
src = textwrap.dedent(src_fmt).format(**src_fmtdict)
code = compile(src, '<string>', 'exec')
six.exec_(code, globals_, locals_)
_wrp_preserve = functools.update_wrapper(locals_['_wrp_preserve'], orig_func)
_utinfo['src'] = src
else:
_wrp_preserve = functools.update_wrapper(wrapper, orig_func)
DEBUG_WRAPPED_DOCSTRING = False
if DEBUG_WRAPPED_DOCSTRING:
new_docstr_fmtstr = util_str.codeblock(
'''
Wrapped function {wrap_name}({orig_name})
orig_argspec = {orig_argspec}
orig_docstr = {orig_docstr}
'''
)
else:
new_docstr_fmtstr = util_str.codeblock(
'''
{orig_docstr}
'''
)
new_docstr = new_docstr_fmtstr.format(
wrap_name=wrap_name, orig_name=orig_name, orig_docstr=orig_docstr,
orig_argspec=orig_argspec)
meta_util_six.set_funcdoc(_wrp_preserve, new_docstr)
_wrp_preserve._utinfo = _utinfo
return _wrp_preserve |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_timestamp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'zone'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'UTC'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp_format'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '21', '29', '35', '53', '74', '96', '100', '172', '184', '229', '353']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'or'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'import_statement', 'children': ['33']}, {'id': '33', 'type': 'dotted_name', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'delorean'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '44']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '%'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'Unknown format: timestamp=%r'"}, {'id': '51', 'type': 'tuple', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57', '68']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'timestamp_format'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'timefmt'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'determine_timestamp_format'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'else_clause', 'children': ['69']}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'timefmt'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'timestamp_format'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '87']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '79'], 'value': 'or'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'timefmt'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'timefmt'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '%'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'unknown timestamp_format=%r'"}; {'id': '94', 'type': 'tuple', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'timestamp_format'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'if_statement', 'children': ['101', '111', '131', '166']}, {'id': '101', 'type': 'boolean_operator', 'children': ['102', '108'], 'value': 'and'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '107'], 'value': '=='}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}, {'id': '109', 'type': 'string', 'children': [], 'value': "'\\x00'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'timestamp_'}, {'id': '115', 'type': 'call', 'children': ['116', '130']}; {'id': '116', 'type': 'attribute', 'children': ['117', '129']}, {'id': '117', 'type': 'call', 'children': ['118', '127']}; {'id': '118', 'type': 'attribute', 'children': ['119', '126']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'\\x00'"}, {'id': '125', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "';'"}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '130', 'type': 'argument_list', 'children': []}, {'id': '131', 'type': 'elif_clause', 'children': ['132', '140']}; {'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'and'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '139'], 'value': '>'}, {'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': 'timestamp'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '19'}; {'id': '140', 'type': 'block', 'children': ['141', '158']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'timestamp_'}; {'id': '144', 'type': 'call', 'children': ['145', '157']}, {'id': '145', 'type': 'attribute', 'children': ['146', '156']}; {'id': '146', 'type': 'call', 'children': ['147', '154']}, {'id': '147', 'type': 'attribute', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '150', 'type': 'slice', 'children': ['151', '152']}, {'id': '151', 'type': 'colon', 'children': []}; {'id': '152', 'type': 'integer', 'children': [], 'value': '19'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '163', 'type': 'slice', 'children': ['164', '165']}; {'id': '164', 'type': 'integer', 'children': [], 'value': '19'}, {'id': '165', 'type': 'colon', 'children': []}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'timestamp_'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'dt_'}, {'id': '175', 'type': 'call', 'children': ['176', '181']}; {'id': '176', 'type': 'attribute', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'strptime'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'timestamp_'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'timefmt'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '186', '223']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}; {'id': '186', 'type': 'block', 'children': ['187', '200', '213']}, {'id': '187', 'type': 'if_statement', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'is'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'zone'}; {'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': 'zone'}, {'id': '195', 'type': 'subscript', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tzname'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'zone'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'local'"}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'zone'}; {'id': '208', 'type': 'subscript', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'tzname'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'dn_'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'delorean'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'Delorean'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'dt_'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'zone'}, {'id': '223', 'type': 'else_clause', 'children': ['224']}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'dn_'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'dt_'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '237', '347']}; {'id': '230', 'type': 'boolean_operator', 'children': ['231', '234'], 'value': 'and'}, {'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'is'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '233', 'type': 'None', 'children': []}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': '=='}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'zone'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'UTC'"}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '240', '340']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}; {'id': '240', 'type': 'block', 'children': ['241', '334']}, {'id': '241', 'type': 'if_statement', 'children': ['242', '245', '307']}; {'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'in'}, {'id': '243', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '245', 'type': 'block', 'children': ['246', '266', '281', '301']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'sign'}, {'id': '249', 'type': 'subscript', 'children': ['250', '263']}; {'id': '250', 'type': 'dictionary', 'children': ['251', '255', '259']}, {'id': '251', 'type': 'pair', 'children': ['252', '253']}; {'id': '252', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '253', 'type': 'unary_operator', 'children': ['254'], 'value': '+'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '255', 'type': 'pair', 'children': ['256', '257']}; {'id': '256', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '257', 'type': 'unary_operator', 'children': ['258'], 'value': '+'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '259', 'type': 'pair', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '261', 'type': 'unary_operator', 'children': ['262'], 'value': '-'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '265', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '271']}; {'id': '268', 'type': 'pattern_list', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'hours'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'seconds'}, {'id': '271', 'type': 'call', 'children': ['272', '279']}; {'id': '272', 'type': 'attribute', 'children': ['273', '278']}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}, {'id': '275', 'type': 'slice', 'children': ['276', '277']}; {'id': '276', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '277', 'type': 'colon', 'children': []}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'delta_'}; {'id': '284', 'type': 'call', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '288', 'type': 'argument_list', 'children': ['289', '295']}, {'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'hours'}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'hours'}, {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'seconds'}, {'id': '297', 'type': 'call', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'seconds'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '304', 'type': 'binary_operator', 'children': ['305', '306'], 'value': '*'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'delta_'}, {'id': '307', 'type': 'else_clause', 'children': ['308']}; {'id': '308', 'type': 'block', 'children': ['309', '312', '320']}, {'id': '309', 'type': 'import_statement', 'children': ['310']}; {'id': '310', 'type': 'dotted_name', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'pytz'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'tzname'}, {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'utc_offset'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '319', 'type': 'argument_list', 'children': []}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '323', 'type': 'call', 'children': ['324', '332']}; {'id': '324', 'type': 'attribute', 'children': ['325', '331']}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'pytz'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'tzname'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'utcoffset'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'dt_'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'assignment', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'dn'}, {'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '-'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'dn_'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '340', 'type': 'else_clause', 'children': ['341']}, {'id': '341', 'type': 'block', 'children': ['342']}; {'id': '342', 'type': 'raise_statement', 'children': ['343']}, {'id': '343', 'type': 'call', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}, {'id': '345', 'type': 'argument_list', 'children': ['346']}; {'id': '346', 'type': 'string', 'children': [], 'value': "'python3 should take care of timezone'"}, {'id': '347', 'type': 'else_clause', 'children': ['348']}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'assignment', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'dn'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'dn_'}, {'id': '353', 'type': 'if_statement', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'use_delorean'}, {'id': '355', 'type': 'block', 'children': ['356', '369']}; {'id': '356', 'type': 'if_statement', 'children': ['357', '361']}, {'id': '357', 'type': 'not_operator', 'children': ['358']}; {'id': '358', 'type': 'comparison_operator', 'children': ['359', '360'], 'value': '!='}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'zone'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'UTC'"}, {'id': '361', 'type': 'block', 'children': ['362']}; {'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': 'dn'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'shift'}, {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'zone'}, {'id': '369', 'type': 'return_statement', 'children': ['370']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'dn'} | def parse_timestamp(timestamp, zone='UTC', timestamp_format=None):
r
if timestamp is None:
return None
use_delorean = True or six.PY2
if use_delorean:
import delorean
if not isinstance(timestamp, six.string_types):
raise NotImplementedError('Unknown format: timestamp=%r' % (timestamp,))
if timestamp_format is None:
timefmt = determine_timestamp_format(timestamp, warn=False)
else:
timefmt = timestamp_format
if timefmt is None or not isinstance(timefmt, six.string_types):
raise AssertionError('unknown timestamp_format=%r' % (timestamp_format,))
utc_offset = None
if len(timestamp) == 20 and '\x00' in timestamp:
timestamp_ = timestamp.replace('\x00', ' ').strip(';').strip()
elif use_delorean and len(timestamp) > 19:
timestamp_ = timestamp[:19].strip(';').strip()
utc_offset = timestamp[19:]
else:
timestamp_ = timestamp
dt_ = datetime.datetime.strptime(timestamp_, timefmt)
if use_delorean:
if zone is None:
zone = time.tzname[0]
if zone == 'local':
zone = time.tzname[0]
dn_ = delorean.Delorean(dt_, zone)
else:
dn_ = dt_
if utc_offset is not None and zone == 'UTC':
if use_delorean:
if ':' in utc_offset:
sign = {' ': +1, '+': +1, '-': -1}[utc_offset[0]]
hours, seconds = utc_offset[1:].split(':')
delta_ = datetime.timedelta(hours=int(hours), seconds=int(seconds))
delta = sign * delta_
else:
import pytz
tzname = utc_offset.strip()
delta = pytz.timezone(tzname).utcoffset(dt_)
dn = dn_ - delta
else:
raise AssertionError('python3 should take care of timezone')
else:
dn = dn_
if use_delorean:
if not zone != 'UTC':
dn.shift(zone)
return dn.datetime |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_cache'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'.cPkl'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'enabled'}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '26', '56', '66', '165', '264']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'None', 'children': []}, {'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': 'verbose'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_CACHE'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}, {'id': '27', 'type': 'boolean_operator', 'children': ['28', '30'], 'value': 'or'}; {'id': '28', 'type': 'not_operator', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'USE_CACHE'}; {'id': '30', 'type': 'not_operator', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'enabled'}; {'id': '32', 'type': 'block', 'children': ['33', '50']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '>'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'[util_cache] ... cache disabled: dpath=%s cfgstr=%r'"}; {'id': '44', 'type': 'tuple', 'children': ['45', '49']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'Cache Loading Is Disabled'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_args2_fpath'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64', '65']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '72', '100']}, {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '72', 'type': 'block', 'children': ['73', '91']}, {'id': '73', 'type': 'if_statement', 'children': ['74', '77']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '>'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'[util_cache] ... cache does not exist: dpath=%r fname=%r cfgstr=%r'"}; {'id': '84', 'type': 'tuple', 'children': ['85', '89', '90']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'}, {'id': '97', 'type': 'string', 'children': [], 'value': "'No such file or directory: %r'"}; {'id': '98', 'type': 'tuple', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '100', 'type': 'else_clause', 'children': ['101']}, {'id': '101', 'type': 'block', 'children': ['102', '120', '125', '134', '149']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '>'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'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': 'binary_operator', 'children': ['112', '113'], 'value': '%'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'[util_cache] ... cache exists: dpath=%r fname=%r cfgstr=%r'"}, {'id': '113', 'type': 'tuple', 'children': ['114', '118', '119']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '120', 'type': 'import_statement', 'children': ['121']}, {'id': '121', 'type': 'aliased_import', 'children': ['122', '124']}; {'id': '122', 'type': 'dotted_name', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'nbytes'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get_file_nBytes'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'big_verbose'}, {'id': '137', 'type': 'boolean_operator', 'children': ['138', '146'], 'value': 'or'}; {'id': '138', 'type': 'parenthesized_expression', 'children': ['139']}, {'id': '139', 'type': 'boolean_operator', 'children': ['140', '143'], 'value': 'and'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '>'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'nbytes'}; {'id': '142', 'type': 'float', 'children': [], 'value': '1E6'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '>'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '>'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'big_verbose'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'}, {'id': '157', 'type': 'string', 'children': [], 'value': "'[util_cache] About to read file of size %s'"}; {'id': '158', 'type': 'tuple', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'byte_str2'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'nbytes'}, {'id': '165', 'type': 'try_statement', 'children': ['166', '198', '240', '252']}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'with_statement', 'children': ['168', '183']}; {'id': '168', 'type': 'with_clause', 'children': ['169']}, {'id': '169', 'type': 'with_item', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'Timer'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '178', 'type': 'boolean_operator', 'children': ['179', '180'], 'value': 'and'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'big_verbose'}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '>'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '3'}, {'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': 'data'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'util_io'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'load_data'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '>'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '197', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '198', 'type': 'except_clause', 'children': ['199', '206']}, {'id': '199', 'type': 'as_pattern', 'children': ['200', '204']}; {'id': '200', 'type': 'tuple', 'children': ['201', '202', '203']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'EOFError'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '204', 'type': 'as_pattern_target', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '206', 'type': 'block', 'children': ['207', '215', '232']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '%'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'CORRUPTED? fpath = %s'"}, {'id': '213', 'type': 'tuple', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '215', 'type': 'if_statement', 'children': ['216', '219']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': '>'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '218', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '%'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'[util_cache] ... cache miss dpath=%s cfgstr=%r'"}; {'id': '226', 'type': 'tuple', 'children': ['227', '231']}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '232', 'type': 'raise_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '240', 'type': 'except_clause', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '242', 'type': 'block', 'children': ['243', '251']}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'CORRUPTED? fpath = %s'"}, {'id': '249', 'type': 'tuple', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '251', 'type': 'raise_statement', 'children': []}; {'id': '252', 'type': 'else_clause', 'children': ['253']}, {'id': '253', 'type': 'block', 'children': ['254']}; {'id': '254', 'type': 'if_statement', 'children': ['255', '258']}, {'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': '>'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'string', 'children': [], 'value': "'[util_cache] ... cache hit'"}; {'id': '264', 'type': 'return_statement', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'data'} | def load_cache(dpath, fname, cfgstr, ext='.cPkl', verbose=None, enabled=True):
if verbose is None:
verbose = VERBOSE_CACHE
if not USE_CACHE or not enabled:
if verbose > 1:
print('[util_cache] ... cache disabled: dpath=%s cfgstr=%r' %
(basename(dpath), cfgstr,))
raise IOError(3, 'Cache Loading Is Disabled')
fpath = _args2_fpath(dpath, fname, cfgstr, ext)
if not exists(fpath):
if verbose > 0:
print('[util_cache] ... cache does not exist: dpath=%r fname=%r cfgstr=%r' % (
basename(dpath), fname, cfgstr,))
raise IOError(2, 'No such file or directory: %r' % (fpath,))
else:
if verbose > 2:
print('[util_cache] ... cache exists: dpath=%r fname=%r cfgstr=%r' % (
basename(dpath), fname, cfgstr,))
import utool as ut
nbytes = ut.get_file_nBytes(fpath)
big_verbose = (nbytes > 1E6 and verbose > 2) or verbose > 2
if big_verbose:
print('[util_cache] About to read file of size %s' % (ut.byte_str2(nbytes),))
try:
with ut.Timer(fpath, verbose=big_verbose and verbose > 3):
data = util_io.load_data(fpath, verbose=verbose > 2)
except (EOFError, IOError, ImportError) as ex:
print('CORRUPTED? fpath = %s' % (fpath,))
if verbose > 1:
print('[util_cache] ... cache miss dpath=%s cfgstr=%r' % (
basename(dpath), cfgstr,))
raise IOError(str(ex))
except Exception:
print('CORRUPTED? fpath = %s' % (fpath,))
raise
else:
if verbose > 2:
print('[util_cache] ... cache hit')
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cached_func'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cache_dir'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'appname'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'utool'"}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key_argx'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key_kwds'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'use_cache'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '28', '37', '325']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_CACHE'}, {'id': '37', 'type': 'function_definition', 'children': ['38', '39', '41']}; {'id': '38', 'type': 'function_name', 'children': [], 'value': 'cached_closure'}, {'id': '39', 'type': 'parameters', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '41', 'type': 'block', 'children': ['42', '47', '52', '66', '75', '84', '100', '116', '139', '307', '317', '323']}; {'id': '42', 'type': 'import_from_statement', 'children': ['43', '45']}, {'id': '43', 'type': 'dotted_name', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '45', 'type': 'dotted_name', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'util_decor'}, {'id': '47', 'type': 'import_statement', 'children': ['48']}; {'id': '48', 'type': 'aliased_import', 'children': ['49', '51']}, {'id': '49', 'type': 'dotted_name', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'fname_'}, {'id': '55', 'type': 'conditional_expression', 'children': ['56', '62', '65'], 'value': 'if'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '64', 'type': 'None', 'children': []}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwdefaults'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_kwdefaults'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'argnames'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_argnames'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '91']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_method'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'func'}, {'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': 'argnames'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'argnames'}, {'id': '97', 'type': 'slice', 'children': ['98', '99']}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'cacher'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Cacher'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107', '110', '113']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'fname_'}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cache_dir'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cache_dir'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'appname'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'appname'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120', '133']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'is'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'use_cache'}, {'id': '119', 'type': 'None', 'children': []}; {'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': 'use_cache_'}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'util_arg'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'--nocache-'"}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'fname_'}, {'id': '133', 'type': 'else_clause', 'children': ['134']}; {'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': 'use_cache_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'use_cache'}, {'id': '139', 'type': 'function_definition', 'children': ['140', '141', '146']}; {'id': '140', 'type': 'function_name', 'children': [], 'value': 'cached_wraper'}, {'id': '141', 'type': 'parameters', 'children': ['142', '144']}; {'id': '142', 'type': 'list_splat_pattern', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '144', 'type': 'dictionary_splat_pattern', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'try_statement', 'children': ['148', '248']}; {'id': '148', 'type': 'block', 'children': ['149', '162', '175', '191', '199', '209', '228', '238', '246']}, {'id': '149', 'type': 'if_statement', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '>'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'[util_cache] computing cached function fname_=%s'"}; {'id': '160', 'type': 'tuple', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'fname_'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get_cfgstr_from_args'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170', '171', '172', '173', '174']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'key_argx'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'key_kwds'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'kwdefaults'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'argnames'}, {'id': '175', 'type': 'if_statement', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'util_cplat'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'util_hash'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'hashstr27'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '191', 'type': 'assert_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'cfgstr=%r cannot be None'"}, {'id': '197', 'type': 'tuple', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'use_cache__'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '208']}, {'id': '207', 'type': 'string', 'children': [], 'value': "'use_cache'"}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'use_cache_'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'use_cache__'}, {'id': '211', 'type': 'block', 'children': ['212', '221']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'cacher'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'tryload'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '225']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '224', 'type': 'None', 'children': []}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'return_statement', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '236']}; {'id': '234', 'type': 'list_splat', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '236', 'type': 'dictionary_splat', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': 'cacher'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'save'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '246', 'type': 'return_statement', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '248', 'type': 'except_clause', 'children': ['249', '253']}, {'id': '249', 'type': 'as_pattern', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '251', 'type': 'as_pattern_target', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '253', 'type': 'block', 'children': ['254', '259', '280', '298', '306']}; {'id': '254', 'type': 'import_from_statement', 'children': ['255', '257']}, {'id': '255', 'type': 'dotted_name', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '257', 'type': 'dotted_name', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': '_dbgdict2'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '268', '274']}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'key_argx'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'key_argx'}; {'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'lenargs'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'lenkw'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'list', 'children': ['289', '290'], 'value': "[\n '+--- UTOOL --- ERROR IN CACHED FUNCTION',\n 'dbgdict2 = ' + util_str.repr4(_dbgdict2),\n ]"}, {'id': '289', 'type': 'string', 'children': [], 'value': "'+--- UTOOL --- ERROR IN CACHED FUNCTION'"}; {'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '+'}, {'id': '291', 'type': 'string', 'children': [], 'value': "'dbgdict2 = '"}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'repr4'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': '_dbgdict2'}; {'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': 'util_dbg'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'printex'}, {'id': '303', 'type': 'argument_list', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '306', 'type': 'raise_statement', 'children': []}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'cached_wraper'}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'util_decor'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'preserve_sig'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'cached_wraper'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'cached_wraper'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'cacher'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'cacher'}, {'id': '323', 'type': 'return_statement', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'cached_wraper'}, {'id': '325', 'type': 'return_statement', 'children': ['326']} | def cached_func(fname=None, cache_dir='default', appname='utool', key_argx=None,
key_kwds=None, use_cache=None, verbose=None):
r
if verbose is None:
verbose = VERBOSE_CACHE
def cached_closure(func):
from utool import util_decor
import utool as ut
fname_ = util_inspect.get_funcname(func) if fname is None else fname
kwdefaults = util_inspect.get_kwdefaults(func)
argnames = util_inspect.get_argnames(func)
if ut.is_method(func):
argnames = argnames[1:]
cacher = Cacher(fname_, cache_dir=cache_dir, appname=appname,
verbose=verbose)
if use_cache is None:
use_cache_ = not util_arg.get_argflag('--nocache-' + fname_)
else:
use_cache_ = use_cache
def cached_wraper(*args, **kwargs):
try:
if verbose > 2:
print('[util_cache] computing cached function fname_=%s' %
( fname_,))
cfgstr = get_cfgstr_from_args(func, args, kwargs, key_argx,
key_kwds, kwdefaults, argnames)
if util_cplat.WIN32:
cfgstr = '_' + util_hash.hashstr27(cfgstr)
assert cfgstr is not None, 'cfgstr=%r cannot be None' % (cfgstr,)
use_cache__ = kwargs.pop('use_cache', use_cache_)
if use_cache__:
data = cacher.tryload(cfgstr)
if data is not None:
return data
data = func(*args, **kwargs)
cacher.save(data, cfgstr)
return data
except Exception as ex:
from utool import util_dbg
_dbgdict2 = dict(key_argx=key_argx, lenargs=len(args),
lenkw=len(kwargs),)
msg = '\n'.join([
'+--- UTOOL --- ERROR IN CACHED FUNCTION',
'dbgdict2 = ' + util_str.repr4(_dbgdict2),
])
util_dbg.printex(ex, msg)
raise
cached_wraper = util_decor.preserve_sig(cached_wraper, func)
cached_wraper.cacher = cacher
return cached_wraper
return cached_closure |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'path_ndir_split'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_unix'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'winroot'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'C:'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'trailing'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '18', '30', '213']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '27']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34', '42', '51']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cplat_path'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ensure_crossplat_path'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '42', 'type': 'elif_clause', 'children': ['43', '46']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '=='}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cplat_path'}; {'id': '50', 'type': 'string', 'children': [], 'value': "''"}, {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53', '62', '66', '70', '74', '144', '179', '194', '201']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '56', 'type': 'conditional_expression', 'children': ['57', '58', '59'], 'value': 'if'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'force_unix'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ndirs_list'}, {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'reached_end'}, {'id': '73', 'type': 'False', 'children': []}; {'id': '74', 'type': 'for_statement', 'children': ['75', '76', '80']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '80', 'type': 'block', 'children': ['81', '90']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'pattern_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94', '135']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '=='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '93', 'type': 'string', 'children': [], 'value': "''"}; {'id': '94', 'type': 'block', 'children': ['95', '134']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99', '104']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '98', 'type': 'string', 'children': [], 'value': "''"}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'reached_end'}, {'id': '103', 'type': 'True', 'children': []}; {'id': '104', 'type': 'else_clause', 'children': ['105']}, {'id': '105', 'type': 'block', 'children': ['106', '123', '130']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '109', 'type': 'conditional_expression', 'children': ['110', '111', '117'], 'value': 'if'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '116'], 'value': '=='}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ndirs_list'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'\\\\/'"}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ndirs_list'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'reached_end'}, {'id': '133', 'type': 'True', 'children': []}; {'id': '134', 'type': 'break_statement', 'children': []}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ndirs_list'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '149']}, {'id': '145', 'type': 'boolean_operator', 'children': ['146', '147'], 'value': 'and'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'trailing'}, {'id': '147', 'type': 'not_operator', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'reached_end'}, {'id': '149', 'type': 'block', 'children': ['150', '159']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '155']}; {'id': '152', 'type': 'pattern_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '166']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '165'], 'value': '=='}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'if_statement', 'children': ['168', '174']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '173'], 'value': '=='}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'reached_end'}; {'id': '178', 'type': 'True', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ndirs'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sep'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ndirs_list'}, {'id': '189', 'type': 'slice', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'colon', 'children': []}, {'id': '191', 'type': 'colon', 'children': []}; {'id': '192', 'type': 'unary_operator', 'children': ['193'], 'value': '-'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'cplat_path'}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ensure_crossplat_path'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ndirs'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '206']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '204'], 'value': 'and'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'trailing'}; {'id': '204', 'type': 'not_operator', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'reached_end'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'cplat_path'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '+'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'.../'"}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cplat_path'}, {'id': '213', 'type': 'return_statement', 'children': ['214']} | def path_ndir_split(path_, n, force_unix=True, winroot='C:', trailing=True):
r
if not isinstance(path_, six.string_types):
return path_
if n is None:
cplat_path = ensure_crossplat_path(path_)
elif n == 0:
cplat_path = ''
else:
sep = '/' if force_unix else os.sep
ndirs_list = []
head = path_
reached_end = False
for nx in range(n):
head, tail = split(head)
if tail == '':
if head == '':
reached_end = True
else:
root = head if len(ndirs_list) == 0 else head.strip('\\/')
ndirs_list.append(root)
reached_end = True
break
else:
ndirs_list.append(tail)
if trailing and not reached_end:
head, tail = split(head)
if len(tail) == 0:
if len(head) == 0:
reached_end = True
ndirs = sep.join(ndirs_list[::-1])
cplat_path = ensure_crossplat_path(ndirs)
if trailing and not reached_end:
cplat_path = '.../' + cplat_path
return cplat_path |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_files_in_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dryrun'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '35', '66', '74', '106', '163', '177']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'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': 'fname_pattern_list'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'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': 'fname_pattern_list'}, {'id': '33', 'type': 'list', 'children': ['34'], 'value': '[fname_pattern_list]'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '39', 'type': 'block', 'children': ['40', '45', '52', '59']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'[util_path] Removing files:'"}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '%'}; {'id': '50', 'type': 'string', 'children': [], 'value': "' * from dpath = %r '"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'}, {'id': '57', 'type': 'string', 'children': [], 'value': "' * with patterns = %r'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'}; {'id': '64', 'type': 'string', 'children': [], 'value': "' * recursive = %r'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'pattern_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'num_removed'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'num_matched'}, {'id': '71', 'type': 'tuple', 'children': ['72', '73']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '80']}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '80', 'type': 'block', 'children': ['81', '88', '96']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '84', 'type': 'parenthesized_expression', 'children': ['85']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'!!! dir = %r does not exist!'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}; {'id': '106', 'type': 'for_statement', 'children': ['107', '111', '117']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'dname_list'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fname_list'}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '117', 'type': 'block', 'children': ['118', '158']}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '121']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fname_pattern'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'fname_pattern_list'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '131']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'fname_list'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fname_pattern'}, {'id': '131', 'type': 'block', 'children': ['132', '136']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'augmented_assignment', 'children': ['134', '135'], 'value': '+='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'num_matched'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'num_removed'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'remove_file'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '147', '150', '153']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'dryrun'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dryrun'}, {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '>'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '161']}, {'id': '159', 'type': 'not_operator', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'break_statement', 'children': []}, {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'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', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'[util_path] ... Removed %d/%d files'"}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'num_removed'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'num_matched'}, {'id': '177', 'type': 'return_statement', 'children': ['178']} | def remove_files_in_dir(dpath, fname_pattern_list='*', recursive=False,
verbose=VERBOSE, dryrun=False, ignore_errors=False):
if isinstance(fname_pattern_list, six.string_types):
fname_pattern_list = [fname_pattern_list]
if verbose > 2:
print('[util_path] Removing files:')
print(' * from dpath = %r ' % dpath)
print(' * with patterns = %r' % fname_pattern_list)
print(' * recursive = %r' % recursive)
num_removed, num_matched = (0, 0)
if not exists(dpath):
msg = ('!!! dir = %r does not exist!' % dpath)
if verbose:
print(msg)
warnings.warn(msg, category=UserWarning)
for root, dname_list, fname_list in os.walk(dpath):
for fname_pattern in fname_pattern_list:
for fname in fnmatch.filter(fname_list, fname_pattern):
num_matched += 1
num_removed += remove_file(join(root, fname),
ignore_errors=ignore_errors,
dryrun=dryrun,
verbose=verbose > 5)
if not recursive:
break
if verbose > 0:
print('[util_path] ... Removed %d/%d files' % (num_removed, num_matched))
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_fpaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpaths'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'QUIET'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'print_caller'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'PRINT_CALLER'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'files'"}; {'id': '20', 'type': 'block', 'children': ['21', '26', '45', '52', '64', '76', '80', '95', '102', '188', '201']}, {'id': '21', 'type': 'import_statement', 'children': ['22']}; {'id': '22', 'type': 'aliased_import', 'children': ['23', '25']}, {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'print_caller'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '44'], 'value': '+'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_caller_name'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '44', 'type': 'string', 'children': [], 'value': "' called remove_fpaths'"}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'n_total'}; {'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': 'fpaths'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_verbose'}, {'id': '55', 'type': 'boolean_operator', 'children': ['56', '63'], 'value': 'or'}; {'id': '56', 'type': 'parenthesized_expression', 'children': ['57']}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '60'], 'value': 'and'}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'n_total'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'VERYVERBOSE'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_verbose'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'[util_path.remove_fpaths] try removing %d %s'"}, {'id': '73', 'type': 'tuple', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'n_total'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'lbl'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'n_removed'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'prog'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ProgIter'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89', '92']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'fpaths'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'removing files'"}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'enabled'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_iter'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '102', 'type': 'try_statement', 'children': ['103', '119']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '107']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_iter'}, {'id': '107', 'type': 'block', 'children': ['108', '115']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'n_removed'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '119', 'type': 'except_clause', 'children': ['120', '124']}; {'id': '120', 'type': 'as_pattern', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '122', 'type': 'as_pattern_target', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '124', 'type': 'block', 'children': ['125', '136', '154']}, {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'VERYVERBOSE'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'WARNING: Could not remove fpath = %r'"}; {'id': '134', 'type': 'tuple', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '138', 'type': 'block', 'children': ['139', '153']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'printex'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146', '150']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'Could not remove fpath = %r'"}; {'id': '148', 'type': 'tuple', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'iswarning'}; {'id': '152', 'type': 'False', 'children': []}, {'id': '153', 'type': 'raise_statement', 'children': []}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '157']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_iter'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'try_statement', 'children': ['159', '171']}, {'id': '159', 'type': 'block', 'children': ['160', '167']}; {'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': 'os'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'augmented_assignment', 'children': ['169', '170'], 'value': '+='}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'n_removed'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '171', 'type': 'except_clause', 'children': ['172', '176']}; {'id': '172', 'type': 'as_pattern', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '174', 'type': 'as_pattern_target', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'if_statement', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'VERYVERBOSE'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'WARNING: Could not remove fpath = %r'"}; {'id': '186', 'type': 'tuple', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': '_verbose'}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'[util_path.remove_fpaths] ... removed %d / %d %s'"}, {'id': '197', 'type': 'tuple', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'n_removed'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'n_total'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '201', 'type': 'return_statement', 'children': ['202']} | def remove_fpaths(fpaths, verbose=VERBOSE, quiet=QUIET, strict=False,
print_caller=PRINT_CALLER, lbl='files'):
import utool as ut
if print_caller:
print(util_dbg.get_caller_name(range(1, 4)) + ' called remove_fpaths')
n_total = len(fpaths)
_verbose = (not quiet and n_total > 0) or VERYVERBOSE
if _verbose:
print('[util_path.remove_fpaths] try removing %d %s' % (n_total, lbl))
n_removed = 0
prog = ut.ProgIter(fpaths, label='removing files', enabled=verbose)
_iter = iter(prog)
try:
for fpath in _iter:
os.remove(fpath)
n_removed += 1
except OSError as ex:
if VERYVERBOSE:
print('WARNING: Could not remove fpath = %r' % (fpath,))
if strict:
util_dbg.printex(ex, 'Could not remove fpath = %r' % (fpath,),
iswarning=False)
raise
for fpath in _iter:
try:
os.remove(fpath)
n_removed += 1
except OSError as ex:
if VERYVERBOSE:
print('WARNING: Could not remove fpath = %r' % (fpath,))
if _verbose:
print('[util_path.remove_fpaths] ... removed %d / %d %s' % (
n_removed, n_total, lbl))
return n_removed |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'checkpath'}, {'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': 'verbose'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'VERYVERBOSE'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'VERYVERBOSE'}; {'id': '14', 'type': 'block', 'children': ['15', '17', '34', '41', '121', '128', '188', '223']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '17', 'type': 'assert_statement', 'children': ['18', '25']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '25', 'type': 'parenthesized_expression', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'path_=%r is not a string. type(path_) = %r'"}; {'id': '28', 'type': 'tuple', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '50']}; {'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': 'sys'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'win32'"}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '58']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '58', 'type': 'block', 'children': ['59', '68']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '68', 'type': 'if_statement', 'children': ['69', '93']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '85'], 'value': 'and'}; {'id': '70', 'type': 'boolean_operator', 'children': ['71', '77'], 'value': 'and'}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '>'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '84'], 'value': '=='}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dirs'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '92'], 'value': '=='}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dirs'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'block', 'children': ['94', '108']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '107'], 'value': '+'}; {'id': '100', 'type': 'call', 'children': ['101', '106']}, {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '106', 'type': 'argument_list', 'children': []}, {'id': '107', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '118', 'type': 'slice', 'children': ['119', '120']}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'colon', 'children': []}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'does_exist'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '130', 'type': 'block', 'children': ['131', '139', '150', '159']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'pretty_path'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'path_ndir_split'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'caller_name'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'util_dbg'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'get_caller_name'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'allow_genexpr'}, {'id': '149', 'type': 'False', 'children': []}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '%'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'[%s] checkpath(%r)'"}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'caller_name'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'pretty_path'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '161', '178']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'does_exist'}, {'id': '161', 'type': 'block', 'children': ['162', '169']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'path_type'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get_path_type'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '%'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'[%s] ...(%s) exists'"}, {'id': '175', 'type': 'tuple', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'caller_name'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'path_type'}; {'id': '178', 'type': 'else_clause', 'children': ['179']}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'[%s] ... does not exist'"}; {'id': '186', 'type': 'parenthesized_expression', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'caller_name'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '193']}, {'id': '189', 'type': 'boolean_operator', 'children': ['190', '192'], 'value': 'and'}; {'id': '190', 'type': 'not_operator', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'does_exist'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '193', 'type': 'block', 'children': ['194', '201', '208', '215']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_longest_path'}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'longest_existing_path'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': '_longest_path_type'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'get_path_type'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': '_longest_path'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'[util_path] ... The longest existing path is: %r'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': '_longest_path'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '%'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'[util_path] ... and has type %r'"}, {'id': '221', 'type': 'tuple', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': '_longest_path_type'}, {'id': '223', 'type': 'return_statement', 'children': ['224']} | def checkpath(path_, verbose=VERYVERBOSE, n=None, info=VERYVERBOSE):
r
assert isinstance(path_, six.string_types), (
'path_=%r is not a string. type(path_) = %r' % (path_, type(path_)))
path_ = normpath(path_)
if sys.platform.startswith('win32'):
if path_.startswith('\\'):
dirs = path_.split('\\')
if len(dirs) > 1 and len(dirs[0]) == 0 and len(dirs[1]) == 1:
dirs[1] = dirs[1].upper() + ':'
path_ = '\\'.join(dirs[1:])
does_exist = exists(path_)
if verbose:
pretty_path = path_ndir_split(path_, n)
caller_name = util_dbg.get_caller_name(allow_genexpr=False)
print('[%s] checkpath(%r)' % (caller_name, pretty_path))
if does_exist:
path_type = get_path_type(path_)
print('[%s] ...(%s) exists' % (caller_name, path_type,))
else:
print('[%s] ... does not exist' % (caller_name))
if not does_exist and info:
_longest_path = longest_existing_path(path_)
_longest_path_type = get_path_type(_longest_path)
print('[util_path] ... The longest existing path is: %r' % _longest_path)
print('[util_path] ... and has type %r' % (_longest_path_type,))
return does_exist |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'glob'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'with_files'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'with_dirs'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'maxdepth'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'fullpath'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'block', 'children': ['29', '31', '59', '66']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'gen'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'iglob'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '42', '45', '48', '51', '54', '57']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'with_files'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'with_files'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'with_dirs'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'with_dirs'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'maxdepth'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'maxdepth'}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'fullpath'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fullpath'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}, {'id': '57', 'type': 'dictionary_splat', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'path_list'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'gen'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path_list'} | def glob(dpath, pattern=None, recursive=False, with_files=True, with_dirs=True,
maxdepth=None, exclude_dirs=[], fullpath=True, **kwargs):
r
gen = iglob(dpath, pattern, recursive=recursive,
with_files=with_files, with_dirs=with_dirs, maxdepth=maxdepth,
fullpath=fullpath, exclude_dirs=exclude_dirs, **kwargs)
path_list = list(gen)
return path_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_images'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'img_dpath_'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ignore_list'}, {'id': '7', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fullpath'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '23', '34', '43', '50', '57', '61', '66', '73', '208', '218']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fullpath'}, {'id': '31', 'type': 'boolean_operator', 'children': ['32', '33'], 'value': 'or'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'fullpath'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'full'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'img_dpath_'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ensure_unicode'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'img_dpath_'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'img_dpath'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'realpath'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'img_dpath_'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ignore_set'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ignore_list'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'gname_list_'}; {'id': '60', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'assertpath'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'img_dpath'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'true_imgpath'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'truepath'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'img_dpath'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '78', '84']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76', '77']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dlist'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'flist'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'true_imgpath'}; {'id': '84', 'type': 'block', 'children': ['85', '94', '102', '118', '203']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ensure_unicode'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'rel_dpath'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'relpath'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'img_dpath'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '116']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'list_comprehension', 'children': ['107', '110']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'in'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ignore_set'}; {'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dirsplit'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'rel_dpath'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'continue_statement', 'children': []}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '124']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'flist'}; {'id': '124', 'type': 'block', 'children': ['125', '134', '148', '164']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ensure_unicode'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '137', 'type': 'call', 'children': ['138', '145']}; {'id': '138', 'type': 'attribute', 'children': ['139', '144']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rel_dpath'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147']}; {'id': '146', 'type': 'string', 'children': [], 'value': "'\\\\'"}, {'id': '147', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '148', 'type': 'if_statement', 'children': ['149', '155']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'gname'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'./'"}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '161', 'type': 'slice', 'children': ['162', '163']}; {'id': '162', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '163', 'type': 'colon', 'children': []}; {'id': '164', 'type': 'if_statement', 'children': ['165', '169']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fpath_has_imgext'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '169', 'type': 'block', 'children': ['170', '176']}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'in'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ignore_set'}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'continue_statement', 'children': []}; {'id': '176', 'type': 'if_statement', 'children': ['177', '178', '194']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'fullpath'}; {'id': '178', 'type': 'block', 'children': ['179', '187']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'gpath'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'img_dpath'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'gname_list_'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'gpath'}; {'id': '194', 'type': 'else_clause', 'children': ['195']}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'gname_list_'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'gname'}, {'id': '203', 'type': 'if_statement', 'children': ['204', '206']}; {'id': '204', 'type': 'not_operator', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'break_statement', 'children': []}; {'id': '208', 'type': 'if_statement', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'gname_list'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'gname_list_'}; {'id': '218', 'type': 'return_statement', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'gname_list'} | def list_images(img_dpath_, ignore_list=[], recursive=False, fullpath=False,
full=None, sort=True):
r
if full is not None:
fullpath = fullpath or full
img_dpath_ = util_str.ensure_unicode(img_dpath_)
img_dpath = realpath(img_dpath_)
ignore_set = set(ignore_list)
gname_list_ = []
assertpath(img_dpath)
true_imgpath = truepath(img_dpath)
for root, dlist, flist in os.walk(true_imgpath):
root = util_str.ensure_unicode(root)
rel_dpath = relpath(root, img_dpath)
if any([dname in ignore_set for dname in dirsplit(rel_dpath)]):
continue
for fname in iter(flist):
fname = util_str.ensure_unicode(fname)
gname = join(rel_dpath, fname).replace('\\', '/')
if gname.startswith('./'):
gname = gname[2:]
if fpath_has_imgext(gname):
if gname in ignore_set:
continue
if fullpath:
gpath = join(img_dpath, gname)
gname_list_.append(gpath)
else:
gname_list_.append(gname)
if not recursive:
break
if sort:
gname_list = sorted(gname_list_)
return gname_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'matching_fpaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '8', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '21', '35']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'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': 'dpath_list'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'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': 'dpath_list'}, {'id': '33', 'type': 'list', 'children': ['34'], 'value': '[dpath_list]'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'for_statement', 'children': ['40', '44', '50']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dname_list'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'fname_list'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '50', 'type': 'block', 'children': ['51', '62', '75', '84', '90', '132']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'subdirs'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pathsplit_full'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'relpath'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '73']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dir_'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}; {'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dir_'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'subdirs'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'continue_statement', 'children': []}, {'id': '75', 'type': 'if_statement', 'children': ['76', '82']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '81'], 'value': 'in'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'continue_statement', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_match'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fname_list'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '106']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '97', 'type': 'generator_expression', 'children': ['98', '103']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_match'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pat'}, {'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pat'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'if_statement', 'children': ['108', '120']}; {'id': '108', 'type': 'not_operator', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '111', 'type': 'generator_expression', 'children': ['112', '117']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': '_match'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pat'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'pat'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '120', 'type': 'block', 'children': ['121', '129']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'yield', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '135']}, {'id': '133', 'type': 'not_operator', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '135', 'type': 'block', 'children': ['136']} | def matching_fpaths(dpath_list, include_patterns, exclude_dirs=[],
greater_exclude_dirs=[], exclude_patterns=[],
recursive=True):
r
if isinstance(dpath_list, six.string_types):
dpath_list = [dpath_list]
for dpath in dpath_list:
for root, dname_list, fname_list in os.walk(dpath):
subdirs = pathsplit_full(relpath(root, dpath))
if any([dir_ in greater_exclude_dirs for dir_ in subdirs]):
continue
if basename(root) in exclude_dirs:
continue
_match = fnmatch.fnmatch
for name in fname_list:
if any(_match(name, pat) for pat in include_patterns):
if not any(_match(name, pat) for pat in exclude_patterns):
fpath = join(root, name)
yield fpath
if not recursive:
break |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sed'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'regexpr'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repl'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '27', 'type': 'block', 'children': ['28', '48', '62', '73', '112', '181', '188', '192', '196', '200', '240', '245', '253', '269']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47'], 'value': "['*.py', '*.pyx', '*.pxi', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.html', '*.tex']"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'*.py'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'*.pyx'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'*.pxi'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'*.cxx'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'*.cpp'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'*.hxx'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'*.hpp'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'*.c'"}, {'id': '45', 'type': 'string', 'children': [], 'value': "'*.h'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'*.html'"}, {'id': '47', 'type': 'string', 'children': [], 'value': "'*.tex'"}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '56', 'type': 'list', 'children': ['57'], 'value': '[os.getcwd()]'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'getcwd'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'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': 'verbose'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'NOT_QUIET'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '77', '106']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}; {'id': '76', 'type': 'None', 'children': []}, {'id': '77', 'type': 'block', 'children': ['78', '84', '88']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_standard_exclude_dnames'}, {'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': 'exclude_dirs'}, {'id': '87', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fpath_generator'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'matching_fpaths'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96', '97', '100', '103']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fpath_generator'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '114', 'type': 'block', 'children': ['115', '123', '131', '139', '147', '155', '163', '168']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'sed-ing %r'"}, {'id': '121', 'type': 'tuple', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'}; {'id': '128', 'type': 'string', 'children': [], 'value': "' * regular expression : %r'"}, {'id': '129', 'type': 'tuple', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'regexpr'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '%'}; {'id': '136', 'type': 'string', 'children': [], 'value': "' * replacement : %r'"}, {'id': '137', 'type': 'tuple', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'repl'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'}; {'id': '144', 'type': 'string', 'children': [], 'value': "' * include_patterns : %r'"}, {'id': '145', 'type': 'tuple', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '%'}; {'id': '152', 'type': 'string', 'children': [], 'value': "' * recursive: %r'"}, {'id': '153', 'type': 'tuple', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "' * force: %r'"}, {'id': '161', 'type': 'tuple', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '163', 'type': 'import_from_statement', 'children': ['164', '166']}; {'id': '164', 'type': 'dotted_name', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '166', 'type': 'dotted_name', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'}, {'id': '173', 'type': 'string', 'children': [], 'value': "' * fpath_list: %s'"}; {'id': '174', 'type': 'tuple', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'repr3'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'regexpr'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'extend_regex'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'regexpr'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'num_changed'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'num_files_checked'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'fpaths_changed'}, {'id': '199', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '200', 'type': 'for_statement', 'children': ['201', '202', '203']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'fpath_generator'}, {'id': '203', 'type': 'block', 'children': ['204', '208', '221']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'augmented_assignment', 'children': ['206', '207'], 'value': '+='}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'num_files_checked'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'changed_lines'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'sedfile'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '215', '216', '217', '218']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'regexpr'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'repl'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '225']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'changed_lines'}; {'id': '224', 'type': 'None', 'children': []}, {'id': '225', 'type': 'block', 'children': ['226', '233']}; {'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': 'fpaths_changed'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'augmented_assignment', 'children': ['235', '236'], 'value': '+='}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'num_changed'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'changed_lines'}; {'id': '240', 'type': 'import_statement', 'children': ['241']}, {'id': '241', 'type': 'aliased_import', 'children': ['242', '244']}; {'id': '242', 'type': 'dotted_name', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '%'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'num_files_checked = %r'"}, {'id': '251', 'type': 'tuple', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'num_files_checked'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'binary_operator', 'children': ['258', '259'], 'value': '%'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'fpaths_changed = %s'"}, {'id': '259', 'type': 'tuple', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'repr3'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'fpaths_changed'}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'total lines changed = %r'"}, {'id': '275', 'type': 'tuple', 'children': ['276']} | def sed(regexpr, repl, force=False, recursive=False, dpath_list=None,
fpath_list=None, verbose=None, include_patterns=None,
exclude_patterns=[]):
if include_patterns is None:
include_patterns = ['*.py', '*.pyx', '*.pxi', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.html', '*.tex']
if dpath_list is None:
dpath_list = [os.getcwd()]
if verbose is None:
verbose = ut.NOT_QUIET
if fpath_list is None:
greater_exclude_dirs = get_standard_exclude_dnames()
exclude_dirs = []
fpath_generator = matching_fpaths(
dpath_list, include_patterns, exclude_dirs,
greater_exclude_dirs=greater_exclude_dirs,
recursive=recursive, exclude_patterns=exclude_patterns)
else:
fpath_generator = fpath_list
if verbose:
print('sed-ing %r' % (dpath_list,))
print(' * regular expression : %r' % (regexpr,))
print(' * replacement : %r' % (repl,))
print(' * include_patterns : %r' % (include_patterns,))
print(' * recursive: %r' % (recursive,))
print(' * force: %r' % (force,))
from utool import util_str
print(' * fpath_list: %s' % (util_str.repr3(fpath_list),))
regexpr = extend_regex(regexpr)
num_changed = 0
num_files_checked = 0
fpaths_changed = []
for fpath in fpath_generator:
num_files_checked += 1
changed_lines = sedfile(fpath, regexpr, repl, force, verbose=verbose)
if changed_lines is not None:
fpaths_changed.append(fpath)
num_changed += len(changed_lines)
import utool as ut
print('num_files_checked = %r' % (num_files_checked,))
print('fpaths_changed = %s' % (ut.repr3(sorted(fpaths_changed)),))
print('total lines changed = %r' % (num_changed,)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'grep'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'regex_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'inverse'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'reflags'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39', '41', '46', '51', '61', '70', '84', '98', '127', '141', '145', '149', '153', '188', '202', '212', '222', '228', '307', '314', '347']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '41', 'type': 'import_from_statement', 'children': ['42', '44']}; {'id': '42', 'type': 'dotted_name', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '44', 'type': 'dotted_name', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'util_regex'}; {'id': '46', 'type': 'import_from_statement', 'children': ['47', '49']}, {'id': '47', 'type': 'dotted_name', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '49', 'type': 'dotted_name', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'util_list'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '59', 'type': 'list', 'children': ['60'], 'value': "['*']"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}; {'id': '64', 'type': 'None', 'children': []}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '69', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '78']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '82', 'type': 'list', 'children': ['83'], 'value': '[include_patterns]'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '87', 'type': 'None', 'children': []}; {'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': 'dpath_list'}; {'id': '92', 'type': 'list', 'children': ['93'], 'value': '[os.getcwd()]'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'getcwd'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '100', 'type': 'block', 'children': ['101', '109', '119']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'recursive_stat_str'}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'list', 'children': ['106', '107'], 'value': "['flat', 'recursive']"}; {'id': '106', 'type': 'string', 'children': [], 'value': "'flat'"}, {'id': '107', 'type': 'string', 'children': [], 'value': "'recursive'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '%'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'[util_path] Greping (%s) %r for %r'"}, {'id': '115', 'type': 'tuple', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'recursive_stat_str'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'regex_list'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '%'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'[util_path] regex_list = %s'"}, {'id': '125', 'type': 'parenthesized_expression', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'regex_list'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '135']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'regex_list'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'regex_list'}, {'id': '139', 'type': 'list', 'children': ['140'], 'value': '[regex_list]'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'regex_list'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'found_fpath_list'}; {'id': '144', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'found_lines_list'}; {'id': '148', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'found_lxs_list'}; {'id': '152', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157', '182']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'is'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}; {'id': '156', 'type': 'None', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'fpath_generator'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'matching_fpaths'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '167', '170', '173', '176', '179']}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'include_patterns'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'exclude_dirs'}, {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'greater_exclude_dirs'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'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': 'fpath_generator'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fpath_list'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_exprs_flags'}, {'id': '191', 'type': 'list_comprehension', 'children': ['192', '199']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'util_regex'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'extend_regex2'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'reflags'}, {'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'regex_list'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'extended_regex_list'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'util_list'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'take_column'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_exprs_flags'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'reflags_list'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'util_list'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'take_column'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '_exprs_flags'}, {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'reflags'}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'reflags_list'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'for_statement', 'children': ['229', '230', '231']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'fpath_generator'}, {'id': '231', 'type': 'block', 'children': ['232', '246']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '237']}; {'id': '234', 'type': 'pattern_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'found_lines'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'found_lxs'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'grepfile'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241', '242', '243']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'extended_regex_list'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'reflags_list'}, {'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '246', 'type': 'if_statement', 'children': ['247', '248', '278']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'inverse'}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'if_statement', 'children': ['250', '256']}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '255'], 'value': '=='}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'found_lines'}, {'id': '255', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '256', 'type': 'block', 'children': ['257', '264', '271']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'found_fpath_list'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'found_lines_list'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'list', 'children': [], 'value': '[]'}, {'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': 'found_lxs_list'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '278', 'type': 'elif_clause', 'children': ['279', '285']}, {'id': '279', 'type': 'comparison_operator', 'children': ['280', '284'], 'value': '>'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'found_lines'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '285', 'type': 'block', 'children': ['286', '293', '300']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'found_fpath_list'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'found_lines_list'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'found_lines'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'found_lxs_list'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'found_lxs'}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'grep_result'}; {'id': '310', 'type': 'tuple', 'children': ['311', '312', '313']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'found_fpath_list'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'found_lines_list'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'found_lxs_list'}; {'id': '314', 'type': 'if_statement', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '316', 'type': 'block', 'children': ['317', '322', '327', '337']}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'string', 'children': [], 'value': "'=========='"}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'string', 'children': [], 'value': "'=========='"}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'binary_operator', 'children': ['332', '333'], 'value': '%'}; {'id': '332', 'type': 'string', 'children': [], 'value': "'[util_path] found matches in %d files'"}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'found_fpath_list'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'call', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'make_grep_resultstr'}, {'id': '343', 'type': 'argument_list', 'children': ['344', '345', '346']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'grep_result'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'extended_regex_list'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'reflags'}, {'id': '347', 'type': 'return_statement', 'children': ['348']} | def grep(regex_list, recursive=True, dpath_list=None, include_patterns=None,
exclude_dirs=[], greater_exclude_dirs=None, inverse=False,
exclude_patterns=[], verbose=VERBOSE, fpath_list=None, reflags=0,
cache=None):
r
from utool import util_regex
from utool import util_list
if include_patterns is None:
include_patterns = ['*']
if greater_exclude_dirs is None:
greater_exclude_dirs = []
if isinstance(include_patterns, six.string_types):
include_patterns = [include_patterns]
if dpath_list is None:
dpath_list = [os.getcwd()]
if verbose:
recursive_stat_str = ['flat', 'recursive'][recursive]
print('[util_path] Greping (%s) %r for %r' % (recursive_stat_str,
dpath_list, regex_list))
print('[util_path] regex_list = %s' % (regex_list))
if isinstance(regex_list, six.string_types):
regex_list = [regex_list]
found_fpath_list = []
found_lines_list = []
found_lxs_list = []
if fpath_list is None:
fpath_generator = matching_fpaths(
dpath_list=dpath_list, include_patterns=include_patterns,
exclude_dirs=exclude_dirs,
greater_exclude_dirs=greater_exclude_dirs,
exclude_patterns=exclude_patterns, recursive=recursive)
else:
fpath_generator = fpath_list
_exprs_flags = [util_regex.extend_regex2(expr, reflags)
for expr in regex_list]
extended_regex_list = util_list.take_column(_exprs_flags, 0)
reflags_list = util_list.take_column(_exprs_flags, 1)
reflags = reflags_list[0]
for fpath in fpath_generator:
found_lines, found_lxs = grepfile(fpath, extended_regex_list,
reflags_list, cache=cache)
if inverse:
if len(found_lines) == 0:
found_fpath_list.append(fpath)
found_lines_list.append([])
found_lxs_list.append([])
elif len(found_lines) > 0:
found_fpath_list.append(fpath)
found_lines_list.append(found_lines)
found_lxs_list.append(found_lxs)
grep_result = (found_fpath_list, found_lines_list, found_lxs_list)
if verbose:
print('==========')
print('==========')
print('[util_path] found matches in %d files' %
len(found_fpath_list))
print(make_grep_resultstr(grep_result, extended_regex_list, reflags))
return grep_result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_lib_fpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'libname'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'recurse_down'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '94', '124', '131', '135', '230', '243', '248', '258']}; {'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'function_name', 'children': [], 'value': 'get_lib_fname_list'}; {'id': '18', 'type': 'parameters', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'libname'}; {'id': '20', 'type': 'block', 'children': ['21', '92']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '30', '43', '62', '81']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'win32'"}; {'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': 'libnames'}; {'id': '34', 'type': 'list', 'children': ['35', '40'], 'value': "['lib' + libname + '.dll', libname + '.dll']"}, {'id': '35', 'type': 'binary_operator', 'children': ['36', '39'], 'value': '+'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'libname'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'.dll'"}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'libname'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'.dll'"}, {'id': '43', 'type': 'elif_clause', 'children': ['44', '52']}; {'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': 'sys'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'darwin'"}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'libnames'}; {'id': '56', 'type': 'list', 'children': ['57'], 'value': "['lib' + libname + '.dylib']"}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '61'], 'value': '+'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'libname'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'.dylib'"}; {'id': '62', 'type': 'elif_clause', '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': 'sys'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'linux'"}, {'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': 'libnames'}, {'id': '75', 'type': 'list', 'children': ['76'], 'value': "['lib' + libname + '.so']"}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '80'], 'value': '+'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'lib'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'libname'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'.so'"}, {'id': '81', 'type': 'else_clause', 'children': ['82']}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'raise_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'Unknown operating system: %s'"}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'libnames'}; {'id': '94', 'type': 'function_definition', 'children': ['95', '96', '98']}, {'id': '95', 'type': 'function_name', 'children': [], 'value': 'get_lib_dpath_list'}; {'id': '96', 'type': 'parameters', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '98', 'type': 'block', 'children': ['99', '101', '122']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'returns possible lib locations'"}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_lib_dpath_list'}; {'id': '104', 'type': 'list', 'children': ['105', '106', '111', '116'], 'value': "[root_dir,\n join(root_dir, 'lib'),\n join(root_dir, 'build'),\n join(root_dir, 'build', 'lib')]"}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'lib'"}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'root_dir'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'build'"}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'build'"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'lib'"}; {'id': '122', 'type': 'return_statement', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_lib_dpath_list'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'lib_fname_list'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_lib_fname_list'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'libname'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tried_fpaths'}; {'id': '134', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '135', 'type': 'while_statement', 'children': ['136', '139']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'is'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '138', 'type': 'None', 'children': []}, {'id': '139', 'type': 'block', 'children': ['140', '225']}; {'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'lib_fname'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'lib_fname_list'}, {'id': '143', 'type': 'block', 'children': ['144', '202', '209']}; {'id': '144', 'type': 'for_statement', 'children': ['145', '146', '150']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'lib_dpath'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_lib_dpath_list'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '150', 'type': 'block', 'children': ['151', '162']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'lib_fpath'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'lib_dpath'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'lib_fname'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '167', '193']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'lib_fpath'}, {'id': '167', 'type': 'block', 'children': ['168', '181', '191']}; {'id': '168', 'type': 'if_statement', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': "'\\n[c] Checked: '"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tried_fpaths'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '%'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'using: %r'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'lib_fpath'}, {'id': '191', 'type': 'return_statement', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lib_fpath'}, {'id': '193', 'type': 'else_clause', 'children': ['194']}; {'id': '194', 'type': 'block', 'children': ['195']}, {'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': 'tried_fpaths'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'lib_fpath'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': '_new_root'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'root_dir'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '213', '219']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': '=='}, {'id': '211', 'type': 'identifier', 'children': [], 'value': '_new_root'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'root_dir'}, {'id': '213', 'type': 'block', 'children': ['214', '218']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'root_dir'}, {'id': '217', 'type': 'None', 'children': []}; {'id': '218', 'type': 'break_statement', 'children': []}, {'id': '219', 'type': 'else_clause', 'children': ['220']}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': '_new_root'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '228']}; {'id': '226', 'type': 'not_operator', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'recurse_down'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'break_statement', 'children': []}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '233', 'type': 'parenthesized_expression', 'children': ['234']}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '242'], 'value': '+'}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '%'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'\\n[C!] load_clib(libname=%r root_dir=%r, recurse_down=%r, verbose=%r)'"}, {'id': '237', 'type': 'tuple', 'children': ['238', '239', '240', '241']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'libname'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'root_dir'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'recurse_down'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'\\n[c!] Cannot FIND dynamic library'"}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': "'\\n[c!] Checked: '"}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'tried_fpaths'}; {'id': '258', 'type': 'raise_statement', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'ImportError'}, {'id': '261', 'type': 'argument_list', 'children': ['262']} | def find_lib_fpath(libname, root_dir, recurse_down=True, verbose=False, debug=False):
def get_lib_fname_list(libname):
if sys.platform.startswith('win32'):
libnames = ['lib' + libname + '.dll', libname + '.dll']
elif sys.platform.startswith('darwin'):
libnames = ['lib' + libname + '.dylib']
elif sys.platform.startswith('linux'):
libnames = ['lib' + libname + '.so']
else:
raise Exception('Unknown operating system: %s' % sys.platform)
return libnames
def get_lib_dpath_list(root_dir):
'returns possible lib locations'
get_lib_dpath_list = [root_dir,
join(root_dir, 'lib'),
join(root_dir, 'build'),
join(root_dir, 'build', 'lib')]
return get_lib_dpath_list
lib_fname_list = get_lib_fname_list(libname)
tried_fpaths = []
while root_dir is not None:
for lib_fname in lib_fname_list:
for lib_dpath in get_lib_dpath_list(root_dir):
lib_fpath = normpath(join(lib_dpath, lib_fname))
if exists(lib_fpath):
if verbose:
print('\n[c] Checked: '.join(tried_fpaths))
if debug:
print('using: %r' % lib_fpath)
return lib_fpath
else:
tried_fpaths.append(lib_fpath)
_new_root = dirname(root_dir)
if _new_root == root_dir:
root_dir = None
break
else:
root_dir = _new_root
if not recurse_down:
break
msg = ('\n[C!] load_clib(libname=%r root_dir=%r, recurse_down=%r, verbose=%r)' %
(libname, root_dir, recurse_down, verbose) +
'\n[c!] Cannot FIND dynamic library')
print(msg)
print('\n[c!] Checked: '.join(tried_fpaths))
raise ImportError(msg) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_candidate_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'candidate_name_list'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'priority_paths'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'required_subpaths'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '23', '35', '45', '76', '87', '91', '169', '179']}; {'id': '18', 'type': 'import_statement', 'children': ['19']}, {'id': '19', 'type': 'aliased_import', 'children': ['20', '22']}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '31', 'type': 'conditional_expression', 'children': ['32', '33', '34'], 'value': 'if'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'QUIET'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '>='}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'[search_candidate_paths] Searching for candidate paths'"}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49', '70']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'candidate_name_list'}; {'id': '48', 'type': 'None', 'children': []}, {'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': 'candidate_path_list_'}, {'id': '53', 'type': 'list_comprehension', 'children': ['54', '59']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '63']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'product'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'candidate_name_list'}; {'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', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list_'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'priority_paths'}, {'id': '79', 'type': 'None', 'children': []}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list_'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'priority_paths'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list_'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'return_path'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'candidate_path_list_'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '104']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '100'], 'value': 'and'}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '104', 'type': 'block', 'children': ['105', '123', '135']}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '>='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '109', 'type': 'block', 'children': ['110', '118']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'[search_candidate_paths] Found candidate directory %r'"}; {'id': '116', 'type': 'tuple', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'[search_candidate_paths] ... checking for approprate structure'"}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'subpath_list'}; {'id': '126', 'type': 'list_comprehension', 'children': ['127', '132']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'subpath'}; {'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'subpath'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'required_subpaths'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '151']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '138', 'type': 'generator_expression', 'children': ['139', '148']}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'path_'}, {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'path_'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'subpath_list'}, {'id': '151', 'type': 'block', 'children': ['152', '156', '166', '168']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'return_path'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '>='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'[search_candidate_paths] Found acceptable path'"}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'return_path'}; {'id': '168', 'type': 'break_statement', 'children': []}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '>='}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'[search_candidate_paths] Failed to find acceptable path'"}, {'id': '179', 'type': 'return_statement', 'children': ['180']} | def search_candidate_paths(candidate_path_list, candidate_name_list=None,
priority_paths=None, required_subpaths=[],
verbose=None):
import utool as ut
if verbose is None:
verbose = 0 if QUIET else 1
if verbose >= 1:
print('[search_candidate_paths] Searching for candidate paths')
if candidate_name_list is not None:
candidate_path_list_ = [join(dpath, fname) for dpath, fname in
itertools.product(candidate_path_list,
candidate_name_list)]
else:
candidate_path_list_ = candidate_path_list
if priority_paths is not None:
candidate_path_list_ = priority_paths + candidate_path_list_
return_path = None
for path in candidate_path_list_:
if path is not None and exists(path):
if verbose >= 2:
print('[search_candidate_paths] Found candidate directory %r' % (path,))
print('[search_candidate_paths] ... checking for approprate structure')
subpath_list = [join(path, subpath) for subpath in required_subpaths]
if all(ut.checkpath(path_, verbose=verbose) for path_ in subpath_list):
return_path = path
if verbose >= 2:
print('[search_candidate_paths] Found acceptable path')
return return_path
break
if verbose >= 1:
print('[search_candidate_paths] Failed to find acceptable path')
return return_path |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'symlink'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'real_path'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'link_path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'on_error'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'raise'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '15', 'type': 'block', 'children': ['16', '23', '30', '44', '132', '213']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'real_path'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'link_path'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'[util_path] Creating symlink: path={} link={}'"}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53']}, {'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': 'os'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'islink'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '53', 'type': 'block', 'children': ['54', '62', '71', '104', '114']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'[util_path] symlink already exists'"}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'os_readlink'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"readlink"'}; {'id': '70', 'type': 'None', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '76', '97']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'os_readlink'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '84']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '83'], 'value': '=='}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'os_readlink'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '84', 'type': 'block', 'children': ['85', '95']}, {'id': '85', 'type': 'if_statement', 'children': ['86', '89']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '>'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'[path] ... and points to the right place'"}, {'id': '95', 'type': 'return_statement', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'[util_path] Warning, symlinks are not implemented on windows'"}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '>'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'[util_path] ... but it points somewhere else'"}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116', '125']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '>'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'elif_clause', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '=='}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'on_error'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'return_statement', 'children': ['131']}, {'id': '131', 'type': 'False', 'children': []}; {'id': '132', 'type': 'try_statement', 'children': ['133', '163']}, {'id': '133', 'type': 'block', 'children': ['134', '143']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'os_symlink'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"symlink"'}; {'id': '142', 'type': 'None', 'children': []}, {'id': '143', 'type': 'if_statement', 'children': ['144', '148', '155']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'os_symlink'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'os_symlink'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '155', 'type': 'else_clause', 'children': ['156']}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'win_shortcut'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '163', 'type': 'except_clause', 'children': ['164', '168']}; {'id': '164', 'type': 'as_pattern', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '166', 'type': 'as_pattern_target', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '168', 'type': 'block', 'children': ['169', '174', '182', '190', '197', '209']}, {'id': '169', 'type': 'import_statement', 'children': ['170']}; {'id': '170', 'type': 'aliased_import', 'children': ['171', '173']}, {'id': '171', 'type': 'dotted_name', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '181', 'type': 'True', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '189', 'type': 'True', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'do_raise'}, {'id': '193', 'type': 'parenthesized_expression', 'children': ['194']}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '=='}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'on_error'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'raise'"}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'printex'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'[util_path] error making symlink'"}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'iswarning'}, {'id': '207', 'type': 'not_operator', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'do_raise'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'do_raise'}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'raise_statement', 'children': []}, {'id': '213', 'type': 'return_statement', 'children': ['214']} | def symlink(real_path, link_path, overwrite=False, on_error='raise',
verbose=2):
path = normpath(real_path)
link = normpath(link_path)
if verbose:
print('[util_path] Creating symlink: path={} link={}'.format(path, link))
if os.path.islink(link):
if verbose:
print('[util_path] symlink already exists')
os_readlink = getattr(os, "readlink", None)
if callable(os_readlink):
if os_readlink(link) == path:
if verbose > 1:
print('[path] ... and points to the right place')
return link
else:
print('[util_path] Warning, symlinks are not implemented on windows')
if verbose > 1:
print('[util_path] ... but it points somewhere else')
if overwrite:
delete(link, verbose > 1)
elif on_error == 'ignore':
return False
try:
os_symlink = getattr(os, "symlink", None)
if callable(os_symlink):
os_symlink(path, link)
else:
win_shortcut(path, link)
except Exception as ex:
import utool as ut
checkpath(link, verbose=True)
checkpath(path, verbose=True)
do_raise = (on_error == 'raise')
ut.printex(ex, '[util_path] error making symlink',
iswarning=not do_raise)
if do_raise:
raise
return link |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'view_directory'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '12', 'type': 'True', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '20', '26', '44', '54', '67', '82', '89', '101', '124', '130', '140']}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'dotted_name', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'util_arg'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'STRICT'}; {'id': '20', 'type': 'import_from_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'dotted_name', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'util_path'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'checkpath'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '36']}, {'id': '27', 'type': 'boolean_operator', 'children': ['28', '29'], 'value': 'and'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'HAVE_PATHLIB'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pathlib'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Path'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'[cplat] view_directory(%r) '"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '57', 'type': 'conditional_expression', 'children': ['58', '63', '66'], 'value': 'if'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'open_prog'}; {'id': '70', 'type': 'subscript', 'children': ['71', '81']}, {'id': '71', 'type': 'dictionary', 'children': ['72', '75', '78']}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'win32'"}; {'id': '74', 'type': 'string', 'children': [], 'value': "'explorer.exe'"}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'linux'"}, {'id': '77', 'type': 'string', 'children': [], 'value': "'nautilus'"}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'darwin'"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'open'"}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'OS_TYPE'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'STRICT'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'assert_statement', 'children': ['93', '100']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'directory doesnt exit'"}, {'id': '101', 'type': 'if_statement', 'children': ['102', '109', '118']}; {'id': '102', 'type': 'boolean_operator', 'children': ['103', '106'], 'value': 'and'}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '=='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'OS_TYPE'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'linux'"}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dname'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '118', 'type': 'else_clause', 'children': ['119']}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dname'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '127', 'type': 'tuple', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'open_prog'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'list2cmdline'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Popen'}, {'id': '145', 'type': 'argument_list', 'children': ['146']} | def view_directory(dname=None, fname=None, verbose=True):
from utool.util_arg import STRICT
from utool.util_path import checkpath
if HAVE_PATHLIB and isinstance(dname, pathlib.Path):
dname = str(dname)
if verbose:
print('[cplat] view_directory(%r) ' % dname)
dname = os.getcwd() if dname is None else dname
open_prog = {
'win32': 'explorer.exe',
'linux': 'nautilus',
'darwin': 'open'
}[OS_TYPE]
dname = normpath(dname)
if STRICT:
assert checkpath(dname, verbose=verbose), 'directory doesnt exit'
if fname is not None and OS_TYPE == 'linux':
arg = join(dname, fname)
else:
arg = dname
args = (open_prog, arg)
print(subprocess.list2cmdline(args))
subprocess.Popen(args) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_cmd_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shell'}, {'id': '7', 'type': 'block', 'children': ['8', '36', '229', '265', '301']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '29']}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '22'], 'value': 'and'}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '16'], 'value': 'and'}, {'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': 'args'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '=='}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'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': 'args'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '38', '127']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'if_statement', 'children': ['40', '47', '49', '74']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'pass_statement', 'children': []}, {'id': '49', 'type': 'elif_clause', 'children': ['50', '64']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '58'], 'value': 'and'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '55', 'type': 'tuple', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'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': 'args'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'args'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '74', 'type': 'elif_clause', 'children': ['75', '89']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '83'], 'value': 'and'}; {'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': 'args'}; {'id': '80', 'type': 'tuple', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'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': 'args'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '100', '110']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'tuple', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '120']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'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': 'args'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'if_statement', 'children': ['130', '137', '151']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'posix'}, {'id': '149', 'type': 'not_operator', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '151', 'type': 'elif_clause', 'children': ['152', '159']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '167', '175']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '166'], 'value': '>'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '175', 'type': 'elif_clause', 'children': ['176', '182']}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '181'], 'value': '=='}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'if_statement', 'children': ['184', '193', '203']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '190']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'tuple', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '203', 'type': 'elif_clause', 'children': ['204', '213']}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '210']}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'posix'}, {'id': '227', 'type': 'not_operator', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '233']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'is'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'sudo'}; {'id': '232', 'type': 'True', 'children': []}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'if_statement', 'children': ['235', '237', '262']}, {'id': '235', 'type': 'not_operator', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '240', '247']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '+'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'sudo '"}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '247', 'type': 'else_clause', 'children': ['248']}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '258'], 'value': '+'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'list', 'children': ['257'], 'value': "['sudo']"}, {'id': '257', 'type': 'string', 'children': [], 'value': "'sudo'"}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'pass_statement', 'children': []}, {'id': '265', 'type': 'if_statement', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '267', 'type': 'block', 'children': ['268']}; {'id': '268', 'type': 'if_statement', 'children': ['269', '285']}, {'id': '269', 'type': 'boolean_operator', 'children': ['270', '276'], 'value': 'and'}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '275'], 'value': '=='}, {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '278', 'type': 'argument_list', 'children': ['279', '282']}, {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '281', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '297']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'posix'}, {'id': '299', 'type': 'not_operator', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'WIN32'}, {'id': '301', 'type': 'return_statement', 'children': ['302']} | def __parse_cmd_args(args, sudo, shell):
if isinstance(args, tuple) and len(args) == 1 and isinstance(args[0], tuple):
args = args[0]
if shell:
if isinstance(args, six.string_types):
pass
elif isinstance(args, (list, tuple)) and len(args) > 1:
args = ' '.join(args)
elif isinstance(args, (list, tuple)) and len(args) == 1:
if isinstance(args[0], (tuple, list)):
args = ' '.join(args)
elif isinstance(args[0], six.string_types):
args = args[0]
else:
if isinstance(args, six.string_types):
args = shlex.split(args, posix=not WIN32)
elif isinstance(args, (list, tuple)):
if len(args) > 1:
args = tuple(args)
elif len(args) == 1:
if isinstance(args[0], (tuple, list)):
args = tuple(args[0])
elif isinstance(args[0], six.string_types):
args = shlex.split(args[0], posix=not WIN32)
if sudo is True:
if not WIN32:
if shell:
args = 'sudo ' + args
else:
args = tuple(['sudo']) + tuple(args)
else:
pass
if WIN32:
if len(args) == 1 and isinstance(args[0], six.string_types):
args = shlex.split(args[0], posix=not WIN32)
return args |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shell'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'detatch'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbout'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '21', '35', '48', '57', '68', '101', '126', '274', '284']}; {'id': '18', 'type': 'import_statement', 'children': ['19']}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'shlex'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '29']}; {'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': 'command'}; {'id': '26', 'type': 'tuple', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'raise_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'command tuple not supported yet'"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'shlex'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'posix'}; {'id': '46', 'type': 'not_operator', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'WIN32'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'verbout'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'verbout'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '>='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '72', 'type': 'block', 'children': ['73', '78', '83', '88']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'+=== START CMD2 ==='"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'Command:'"}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'verbout'}; {'id': '90', 'type': 'block', 'children': ['91', '96']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'----'"}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'Stdout:'"}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110', '115', '120', '123']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'PIPE'}, {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'STDOUT'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'shell'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'universal_newlines'}, {'id': '125', 'type': 'True', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '128', '136']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'detatch'}; {'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': 'info'}; {'id': '132', 'type': 'dictionary', 'children': ['133']}, {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'proc'"}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '136', 'type': 'else_clause', 'children': ['137']}, {'id': '137', 'type': 'block', 'children': ['138', '146', '154', '158', '201', '243', '253', '261']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'write_fn'}, {'id': '141', 'type': 'attribute', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'flush_fn'}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'flush'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'logged_out'}, {'id': '157', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '158', 'type': 'for_statement', 'children': ['159', '160', '164']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_run_process'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '164', 'type': 'block', 'children': ['165', '174']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'line_'}; {'id': '168', 'type': 'conditional_expression', 'children': ['169', '170', '173'], 'value': 'if'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '181']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '>'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'line_'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '181', 'type': 'block', 'children': ['182', '194']}; {'id': '182', 'type': 'if_statement', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'verbout'}; {'id': '184', 'type': 'block', 'children': ['185', '190']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'write_fn'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'line_'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'flush_fn'}, {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'logged_out'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '201', 'type': 'try_statement', 'children': ['202', '217']}; {'id': '202', 'type': 'block', 'children': ['203', '208']}, {'id': '203', 'type': 'import_from_statement', 'children': ['204', '206']}; {'id': '204', 'type': 'dotted_name', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '206', 'type': 'dotted_name', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'util_str'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'string', 'children': [], 'value': "''"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'logged_out'}, {'id': '217', 'type': 'except_clause', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}, {'id': '219', 'type': 'block', 'children': ['220', '225', '234']}; {'id': '220', 'type': 'import_from_statement', 'children': ['221', '223']}, {'id': '221', 'type': 'dotted_name', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '223', 'type': 'dotted_name', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'logged_out'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'util_str'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ensure_unicode_strlist'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'logged_out'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'string', 'children': [], 'value': "''"}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'logged_out'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}, {'id': '245', 'type': 'tuple_pattern', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'out_'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '252', 'type': 'argument_list', 'children': []}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'wait'}; {'id': '260', 'type': 'argument_list', 'children': []}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '264', 'type': 'dictionary', 'children': ['265', '268', '271']}, {'id': '265', 'type': 'pair', 'children': ['266', '267']}; {'id': '266', 'type': 'string', 'children': [], 'value': "'out'"}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '268', 'type': 'pair', 'children': ['269', '270']}, {'id': '269', 'type': 'string', 'children': [], 'value': "'err'"}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '271', 'type': 'pair', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'ret'"}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '274', 'type': 'if_statement', 'children': ['275', '278']}, {'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': '>='}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '278', 'type': 'block', 'children': ['279']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'string', 'children': [], 'value': "'L___ END CMD2 ___'"}; {'id': '284', 'type': 'return_statement', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'info'} | def cmd2(command, shell=False, detatch=False, verbose=False, verbout=None):
import shlex
if isinstance(command, (list, tuple)):
raise ValueError('command tuple not supported yet')
args = shlex.split(command, posix=not WIN32)
if verbose is True:
verbose = 2
if verbout is None:
verbout = verbose >= 1
if verbose >= 2:
print('+=== START CMD2 ===')
print('Command:')
print(command)
if verbout:
print('----')
print('Stdout:')
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=shell,
universal_newlines=True)
if detatch:
info = {'proc': proc}
else:
write_fn = sys.stdout.write
flush_fn = sys.stdout.flush
logged_out = []
for line in _run_process(proc):
line_ = line if six.PY2 else line
if len(line_) > 0:
if verbout:
write_fn(line_)
flush_fn()
logged_out.append(line)
try:
from utool import util_str
out = ''.join(logged_out)
except UnicodeDecodeError:
from utool import util_str
logged_out = util_str.ensure_unicode_strlist(logged_out)
out = ''.join(logged_out)
(out_, err) = proc.communicate()
ret = proc.wait()
info = {
'out': out,
'err': err,
'ret': ret,
}
if verbose >= 2:
print('L___ END CMD2 ___')
return info |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_env_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key_list'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '19', '52', '61', '103']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'import_statement', 'children': ['15']}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key_list'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '44']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key_list'}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '29', '34']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '34', 'type': 'if_clause', 'children': ['35']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '42'], 'value': '>'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'PATH'"}; {'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'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']}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'key_list = %r'"}; {'id': '50', 'type': 'tuple', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key_list'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ddict'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'key_list'}; {'id': '64', 'type': 'block', 'children': ['65', '80']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}; {'id': '68', 'type': 'call', 'children': ['69', '76']}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pathsep'}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dpath_list'}, {'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': 'matches'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dpath'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'found'} | def search_env_paths(fname, key_list=None, verbose=None):
r
import utool as ut
if key_list is None:
key_list = [key for key in os.environ if key.find('PATH') > -1]
print('key_list = %r' % (key_list,))
found = ut.ddict(list)
for key in key_list:
dpath_list = os.environ[key].split(os.pathsep)
for dpath in dpath_list:
matches = ut.glob(dpath, fname)
found[key].extend(matches)
return dict(found) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'partition_varied_cfg_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cfg_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default_cfg'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '19', '49', '60', '78', '185']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'import_statement', 'children': ['15']}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23', '34']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'default_cfg'}; {'id': '22', 'type': 'None', 'children': []}, {'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': 'nonvaried_cfg'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'reduce'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dict_intersection'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cfg_list'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'nonvaried_cfg'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'reduce'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict_intersection'}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '48'], 'value': '+'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[default_cfg]'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'default_cfg'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cfg_list'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'nonvaried_keys'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'nonvaried_cfg'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'varied_cfg_list'}, {'id': '63', 'type': 'list_comprehension', 'children': ['64', '75']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'delete_dict_keys'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '74']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'nonvaried_keys'}, {'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cfg_list'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '80', 'type': 'block', 'children': ['81', '98', '116']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'varied_keys'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '92', '95']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'varied_cfg_list'}, {'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'varied_vals_list'}, {'id': '101', 'type': 'list_comprehension', 'children': ['102', '113']}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '106', '109']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'varied_cfg_list'}, {'id': '109', 'type': 'if_clause', 'children': ['110']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'varied_keys'}; {'id': '116', 'type': 'for_statement', 'children': ['117', '120', '125']}, {'id': '117', 'type': 'pattern_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'varied_vals'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'varied_keys'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'varied_vals_list'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'if_statement', 'children': ['127', '136']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '132'], 'value': '=='}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'varied_vals'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'cfg_list'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'if_statement', 'children': ['138', '150']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'list_comprehension', 'children': ['142', '147']}; {'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': 'val'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '147', 'type': 'for_in_clause', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'varied_vals'}; {'id': '150', 'type': 'block', 'children': ['151', '163', '169']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'pattern_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'nonvaried_subdict'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'varied_subdicts'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'partition_varied_cfg_list'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'varied_vals'}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'recursive'}, {'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': 'nonvaried_cfg'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'nonvaried_subdict'}, {'id': '169', 'type': 'for_statement', 'children': ['170', '173', '178']}; {'id': '170', 'type': 'pattern_list', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'subdict'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'varied_cfg_list'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'varied_subdicts'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'subdict'}, {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'expression_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'nonvaried_cfg'} | def partition_varied_cfg_list(cfg_list, default_cfg=None, recursive=False):
r
import utool as ut
if default_cfg is None:
nonvaried_cfg = reduce(ut.dict_intersection, cfg_list)
else:
nonvaried_cfg = reduce(ut.dict_intersection, [default_cfg] + cfg_list)
nonvaried_keys = list(nonvaried_cfg.keys())
varied_cfg_list = [
ut.delete_dict_keys(cfg.copy(), nonvaried_keys)
for cfg in cfg_list]
if recursive:
varied_keys = list(set([key for cfg in varied_cfg_list for key in cfg]))
varied_vals_list = [[cfg[key] for cfg in varied_cfg_list if key in cfg] for key in varied_keys]
for key, varied_vals in zip(varied_keys, varied_vals_list):
if len(varied_vals) == len(cfg_list):
if all([isinstance(val, dict) for val in varied_vals]):
nonvaried_subdict, varied_subdicts = partition_varied_cfg_list(varied_vals, recursive=recursive)
nonvaried_cfg[key] = nonvaried_subdict
for cfg, subdict in zip(varied_cfg_list, varied_subdicts):
cfg[key] = subdict
return nonvaried_cfg, varied_cfg_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_cfgstr_list2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cfgstr_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cfgtype'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'alias_keys'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'valid_keys'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '22', 'type': 'True', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'special_join_dict'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'is_nestedcfgtype'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '35', '40', '44', '48', '52', '126', '142', '433']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '35', 'type': 'import_statement', 'children': ['36']}; {'id': '36', 'type': 'aliased_import', 'children': ['37', '39']}, {'id': '37', 'type': 'dotted_name', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cfg_combos_list'}, {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'cfgstr_list_'}, {'id': '47', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dyndef_named_defaults'}, {'id': '51', 'type': 'dictionary', 'children': []}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'cfgstr_list'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '66', '117']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '64'], 'value': '>'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'string', 'children': [], 'value': "'=:'"}; {'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '-'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'block', 'children': ['67', '77', '84', '93', '104', '111']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '73']}, {'id': '69', 'type': 'pattern_list', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cfgname'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cfgopt_strs'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'subx'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'parse_cfgstr_name_options'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '77', 'type': 'assert_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cfgname'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cfgname'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cfgname'}, {'id': '89', 'type': 'slice', 'children': ['90', '91']}; {'id': '90', 'type': 'colon', 'children': []}, {'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'base_cfg_list'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'lookup_base_cfg_list'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'cfgname'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cfg_options'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'noexpand_parse_cfgstrs'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'cfgopt_strs'}, {'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': 'dyndef_named_defaults'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'cfgname'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'cfg_options'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'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': 'cfgstr_list_'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '137']}, {'id': '127', 'type': 'boolean_operator', 'children': ['128', '134'], 'value': 'and'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '133'], 'value': '>'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dyndef_named_defaults'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}; {'id': '136', 'type': 'None', 'children': []}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'dyndef_named_defaults'}; {'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'cfgstr_list_'}, {'id': '145', 'type': 'block', 'children': ['146', '150', '423']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}, {'id': '149', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '160', '260']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '158'], 'value': '>'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'::'"}; {'id': '158', 'type': 'unary_operator', 'children': ['159'], 'value': '-'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'block', 'children': ['161', '170', '201', '221', '241']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'special_cfgstr_list'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'::'"}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'special_combo_list'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'parse_cfgstr_list2'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '180', '183', '186', '189', '192', '195', '198']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'special_cfgstr_list'}, {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'cfgtype'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'cfgtype'}, {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'alias_keys'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'alias_keys'}; {'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'valid_keys'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'valid_keys'}, {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}, {'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'is_nestedcfgtype'}, {'id': '197', 'type': 'False', 'children': []}; {'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '205']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'special_join_dict'}; {'id': '204', 'type': 'None', 'children': []}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'for_statement', 'children': ['207', '208', '209']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'special_combo'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'special_combo_list'}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'for_statement', 'children': ['211', '212', '213']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'special_combo'}, {'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': 'cfg'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'special_join_dict'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '223', '235']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'is_nestedcfgtype'}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'list_comprehension', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'combo'}; {'id': '232', 'type': 'for_in_clause', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'combo'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'special_combo_list'}, {'id': '235', 'type': 'else_clause', 'children': ['236']}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'special_combo_list'}, {'id': '241', 'type': 'if_statement', 'children': ['242', '243', '251']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}, {'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', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'cfg_combos_list'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}, {'id': '261', 'type': 'block', 'children': ['262', '272', '304']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '268']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266', '267']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'cfgname'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'cfgopt_strs'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'subx'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'parse_cfgstr_name_options'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'cfgstr'}; {'id': '272', 'type': 'try_statement', 'children': ['273', '285']}, {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'base_cfg_list'}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'lookup_base_cfg_list'}, {'id': '279', 'type': 'argument_list', 'children': ['280', '281', '282']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'cfgname'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'named_defaults_dict'}; {'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '285', 'type': 'except_clause', 'children': ['286', '290']}; {'id': '286', 'type': 'as_pattern', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '288', 'type': 'as_pattern_target', 'children': ['289']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '290', 'type': 'block', 'children': ['291', '303']}, {'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': 'ut'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'printex'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '300', 'type': 'list', 'children': ['301', '302'], 'value': "['cfgstr_list', 'cfgstr_list_']"}, {'id': '301', 'type': 'string', 'children': [], 'value': "'cfgstr_list'"}; {'id': '302', 'type': 'string', 'children': [], 'value': "'cfgstr_list_'"}, {'id': '303', 'type': 'raise_statement', 'children': []}; {'id': '304', 'type': 'for_statement', 'children': ['305', '306', '307']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'base_cfg'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'base_cfg_list'}, {'id': '307', 'type': 'block', 'children': ['308', '316', '324', '332', '340', '348', '359', '367', '375', '396', '404']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'binary_operator', 'children': ['313', '314'], 'value': '%'}, {'id': '313', 'type': 'string', 'children': [], 'value': "'cfgname = %r'"}; {'id': '314', 'type': 'tuple', 'children': ['315']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'cfgname'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '%'}, {'id': '321', 'type': 'string', 'children': [], 'value': "'cfgopt_strs = %r'"}; {'id': '322', 'type': 'tuple', 'children': ['323']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'cfgopt_strs'}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'binary_operator', 'children': ['329', '330'], 'value': '%'}, {'id': '329', 'type': 'string', 'children': [], 'value': "'base_cfg = %r'"}; {'id': '330', 'type': 'tuple', 'children': ['331']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'base_cfg'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '%'}, {'id': '337', 'type': 'string', 'children': [], 'value': "'alias_keys = %r'"}; {'id': '338', 'type': 'tuple', 'children': ['339']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'alias_keys'}; {'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': 'binary_operator', 'children': ['345', '346'], 'value': '%'}, {'id': '345', 'type': 'string', 'children': [], 'value': "'cfgtype = %r'"}; {'id': '346', 'type': 'tuple', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'cfgtype'}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'call', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '351', 'type': 'argument_list', 'children': ['352']}; {'id': '352', 'type': 'binary_operator', 'children': ['353', '354'], 'value': '%'}, {'id': '353', 'type': 'string', 'children': [], 'value': "'offset = %r'"}; {'id': '354', 'type': 'tuple', 'children': ['355']}, {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}, {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'call', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}, {'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '%'}; {'id': '364', 'type': 'string', 'children': [], 'value': "'valid_keys = %r'"}, {'id': '365', 'type': 'tuple', 'children': ['366']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'valid_keys'}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'binary_operator', 'children': ['372', '373'], 'value': '%'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'strict = %r'"}, {'id': '373', 'type': 'tuple', 'children': ['374']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '378', 'type': 'call', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'customize_base_cfg'}; {'id': '380', 'type': 'argument_list', 'children': ['381', '382', '383', '384', '385', '386', '387', '390']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'cfgname'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'cfgopt_strs'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'base_cfg'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'cfgtype'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'alias_keys'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'valid_keys'}, {'id': '387', 'type': 'keyword_argument', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '392', 'type': 'call', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}; {'id': '396', 'type': 'if_statement', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'is_nestedcfgtype'}; {'id': '398', 'type': 'block', 'children': ['399']}, {'id': '399', 'type': 'expression_statement', 'children': ['400']}; {'id': '400', 'type': 'assignment', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '402', 'type': 'list', 'children': ['403'], 'value': '[cfg_combo]'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '404', 'type': 'if_statement', 'children': ['405', '406', '414']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}; {'id': '406', 'type': 'block', 'children': ['407']}, {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'call', 'children': ['409', '412']}, {'id': '409', 'type': 'attribute', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '412', 'type': 'argument_list', 'children': ['413']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}; {'id': '414', 'type': 'else_clause', 'children': ['415']}, {'id': '415', 'type': 'block', 'children': ['416']}; {'id': '416', 'type': 'expression_statement', 'children': ['417']}, {'id': '417', 'type': 'call', 'children': ['418', '421']}; {'id': '418', 'type': 'attribute', 'children': ['419', '420']}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'cfg_combos_list'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '421', 'type': 'argument_list', 'children': ['422']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'cfg_combo'}, {'id': '423', 'type': 'if_statement', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'expand_nested'}, {'id': '425', 'type': 'block', 'children': ['426']}; {'id': '426', 'type': 'expression_statement', 'children': ['427']}, {'id': '427', 'type': 'call', 'children': ['428', '431']}; {'id': '428', 'type': 'attribute', 'children': ['429', '430']}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'cfg_combos_list'}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '431', 'type': 'argument_list', 'children': ['432']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'cfg_combos'}, {'id': '433', 'type': 'return_statement', 'children': ['434']} | def parse_cfgstr_list2(cfgstr_list, named_defaults_dict=None, cfgtype=None,
alias_keys=None, valid_keys=None, expand_nested=True,
strict=True, special_join_dict=None, is_nestedcfgtype=False,
metadata=None):
r
import utool as ut
cfg_combos_list = []
cfgstr_list_ = []
dyndef_named_defaults = {}
for cfgstr in cfgstr_list:
if cfgstr.find('=:') > -1:
cfgname, cfgopt_strs, subx = parse_cfgstr_name_options(cfgstr)
assert cfgname.endswith('=')
cfgname = cfgname[:-1]
base_cfg_list = lookup_base_cfg_list(cfgname,
named_defaults_dict,
metadata=metadata)
cfg_options = noexpand_parse_cfgstrs(cfgopt_strs)
dyndef_named_defaults[cfgname] = cfg_options
else:
cfgstr_list_.append(cfgstr)
if len(dyndef_named_defaults) > 0 and named_defaults_dict is None:
named_defaults_dict = dyndef_named_defaults
for cfgstr in cfgstr_list_:
cfg_combos = []
if cfgstr.find('::') > -1:
special_cfgstr_list = cfgstr.split('::')
special_combo_list = parse_cfgstr_list2(
special_cfgstr_list,
named_defaults_dict=named_defaults_dict, cfgtype=cfgtype,
alias_keys=alias_keys, valid_keys=valid_keys,
strict=strict, expand_nested=expand_nested,
is_nestedcfgtype=False, metadata=metadata)
if special_join_dict is not None:
for special_combo in special_combo_list:
for cfg in special_combo:
cfg.update(special_join_dict)
if is_nestedcfgtype:
cfg_combo = tuple([combo for combo in special_combo_list])
else:
cfg_combo = special_combo_list
if expand_nested:
cfg_combos.extend(cfg_combo)
else:
cfg_combos_list.append(cfg_combo)
else:
cfgname, cfgopt_strs, subx = parse_cfgstr_name_options(cfgstr)
try:
base_cfg_list = lookup_base_cfg_list(cfgname,
named_defaults_dict,
metadata=metadata)
except Exception as ex:
ut.printex(ex, keys=['cfgstr_list', 'cfgstr_list_'])
raise
for base_cfg in base_cfg_list:
print('cfgname = %r' % (cfgname,))
print('cfgopt_strs = %r' % (cfgopt_strs,))
print('base_cfg = %r' % (base_cfg,))
print('alias_keys = %r' % (alias_keys,))
print('cfgtype = %r' % (cfgtype,))
print('offset = %r' % (len(cfg_combos),))
print('valid_keys = %r' % (valid_keys,))
print('strict = %r' % (strict,))
cfg_combo = customize_base_cfg(
cfgname, cfgopt_strs, base_cfg, cfgtype, alias_keys,
valid_keys, strict=strict, offset=len(cfg_combos))
if is_nestedcfgtype:
cfg_combo = [cfg_combo]
if expand_nested:
cfg_combos.extend(cfg_combo)
else:
cfg_combos_list.append(cfg_combo)
if expand_nested:
cfg_combos_list.append(cfg_combos)
return cfg_combos_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gridsearch_timer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func_list'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args_list'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'niters'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'searchkw'}, {'id': '11', 'type': 'block', 'children': ['12', '17', '26', '38', '58', '77', '95', '105', '115', '119', '131', '291', '297', '311', '326', '376', '386']}; {'id': '12', 'type': 'import_statement', 'children': ['13']}, {'id': '13', 'type': 'aliased_import', 'children': ['14', '16']}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'timings'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ddict'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'niters'}, {'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': 'niters'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'args_list'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '45', '50']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'is_funclike'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'args_list'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_args'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'args_list'}; {'id': '50', 'type': 'else_clause', 'children': ['51']}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_args'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args_list'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '__getitem__'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'func_labels'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'searchkw'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'func_labels'"}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '74']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'func_list'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'use_cache'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'searchkw'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'use_cache'"}; {'id': '86', 'type': 'not_operator', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'tuple', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'--nocache'"}; {'id': '94', 'type': 'string', 'children': [], 'value': "'--nocache-time'"}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'assert_eq'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'searchkw'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'assert_eq'"}; {'id': '104', 'type': 'True', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'count_list'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'niters'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'xlabel_list'}; {'id': '118', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ShelfCacher'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'timeings.shelf'"}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'enabled'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'use_cache'}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '142']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ProgressIter'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'count_list'}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'lbl'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'Testing Timeings'"}; {'id': '142', 'type': 'block', 'children': ['143', '150', '157', '173', '180', '184', '272']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_args'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'count'}; {'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': 'xlabel_list'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'args_'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '159']}; {'id': '158', 'type': 'True', 'children': []}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '167']}, {'id': '161', 'type': 'not_operator', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'args_'}, {'id': '171', 'type': 'tuple', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'args_'}, {'id': '173', 'type': 'assert_statement', 'children': ['174', '179']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'args_ should be a tuple so it can be unpacked'"}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ret_list'}, {'id': '183', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '184', 'type': 'for_statement', 'children': ['185', '186', '187']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'func_'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'func_list'}, {'id': '187', 'type': 'block', 'children': ['188', '263']}; {'id': '188', 'type': 'try_statement', 'children': ['189', '214']}, {'id': '189', 'type': 'block', 'children': ['190', '194', '205']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'kwargs_'}, {'id': '193', 'type': 'dictionary', 'children': []}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'func_cachekey'}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'get_func_result_cachekey'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'func_'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'kwargs_'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'ellapsed'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'func_cachekey'}; {'id': '214', 'type': 'except_clause', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'CacheMissException'}; {'id': '218', 'type': 'block', 'children': ['219', '249', '255']}, {'id': '219', 'type': 'with_statement', 'children': ['220', '233']}; {'id': '220', 'type': 'with_clause', 'children': ['221']}, {'id': '221', 'type': 'with_item', 'children': ['222']}; {'id': '222', 'type': 'as_pattern', 'children': ['223', '231']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'Timer'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '230', 'type': 'False', 'children': []}, {'id': '231', 'type': 'as_pattern_target', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '233', 'type': 'block', 'children': ['234', '242']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'func_'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'list_splat', 'children': ['241']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'args_'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ret_list'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ellapsed'}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'ellapsed'}, {'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': 'cache'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'func_cachekey'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'ellapsed'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '270']}, {'id': '265', 'type': 'attribute', 'children': ['266', '269']}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'timings'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'func_'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'ellapsed'}; {'id': '272', 'type': 'if_statement', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'assert_eq'}; {'id': '274', 'type': 'block', 'children': ['275']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'assert_all_eq'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'cachestr_repr'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ret_list'}, {'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': 'cache'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '296', 'type': 'argument_list', 'children': []}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'count_to_xtick'}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'searchkw'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '306']}, {'id': '305', 'type': 'string', 'children': [], 'value': "'count_to_xtick'"}; {'id': '306', 'type': 'lambda', 'children': ['307', '310']}, {'id': '307', 'type': 'lambda_parameters', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'xtick_list'}; {'id': '314', 'type': 'list_comprehension', 'children': ['315', '323']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'count_to_xtick'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'get_args'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '323', 'type': 'for_in_clause', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'count_list'}; {'id': '326', 'type': 'function_definition', 'children': ['327', '328', '329']}, {'id': '327', 'type': 'function_name', 'children': [], 'value': 'plot_timings'}; {'id': '328', 'type': 'parameters', 'children': []}, {'id': '329', 'type': 'block', 'children': ['330', '335', '345', '349', '353', '357']}; {'id': '330', 'type': 'import_statement', 'children': ['331']}, {'id': '331', 'type': 'aliased_import', 'children': ['332', '334']}; {'id': '332', 'type': 'dotted_name', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'plottool'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'pt'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'ydata_list'}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'dict_take'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'timings'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'func_list'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'xdata'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'xtick_list'}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'assignment', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'ylabel'}; {'id': '352', 'type': 'string', 'children': [], 'value': "'seconds'"}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'xlabel'}; {'id': '356', 'type': 'string', 'children': [], 'value': "'input size'"}, {'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': 'pt'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'multi_plot'}; {'id': '362', 'type': 'argument_list', 'children': ['363', '364', '365', '368', '371', '374']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'xdata'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'ydata_list'}, {'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'label_list'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'func_labels'}; {'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'ylabel'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'ylabel'}, {'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'xlabel'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'xlabel'}; {'id': '374', 'type': 'dictionary_splat', 'children': ['375']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'searchkw'}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'time_result'}, {'id': '379', 'type': 'dictionary', 'children': ['380', '383']}; {'id': '380', 'type': 'pair', 'children': ['381', '382']}, {'id': '381', 'type': 'string', 'children': [], 'value': "'plot_timings'"}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'plot_timings'}, {'id': '383', 'type': 'pair', 'children': ['384', '385']}; {'id': '384', 'type': 'string', 'children': [], 'value': "'timings'"}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'timings'}; {'id': '386', 'type': 'return_statement', 'children': ['387']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'time_result'} | def gridsearch_timer(func_list, args_list, niters=None, **searchkw):
import utool as ut
timings = ut.ddict(list)
if niters is None:
niters = len(args_list)
if ut.is_funclike(args_list):
get_args = args_list
else:
get_args = args_list.__getitem__
func_labels = searchkw.get('func_labels', [ut.get_funcname(func) for func in func_list])
use_cache = searchkw.get('use_cache', not ut.get_argflag(('--nocache', '--nocache-time')))
assert_eq = searchkw.get('assert_eq', True)
count_list = list(range(niters))
xlabel_list = []
cache = ut.ShelfCacher('timeings.shelf', enabled=use_cache)
for count in ut.ProgressIter(count_list, lbl='Testing Timeings'):
args_ = get_args(count)
xlabel_list.append(args_)
if True:
if not isinstance(args_, tuple):
args_ = (args_,)
assert isinstance(args_, tuple), 'args_ should be a tuple so it can be unpacked'
ret_list = []
for func_ in func_list:
try:
kwargs_ = {}
func_cachekey = ut.get_func_result_cachekey(func_, args_, kwargs_)
ellapsed = cache.load(func_cachekey)
except ut.CacheMissException:
with ut.Timer(verbose=False) as t:
ret = func_(*args_)
ret_list.append(ret)
ellapsed = t.ellapsed
cache.save(func_cachekey, ellapsed)
timings[func_].append(ellapsed)
if assert_eq:
ut.assert_all_eq(list(map(ut.cachestr_repr, ret_list)))
cache.close()
count_to_xtick = searchkw.get('count_to_xtick', lambda x, y: x)
xtick_list = [count_to_xtick(count, get_args(count)) for count in count_list]
def plot_timings():
import plottool as pt
ydata_list = ut.dict_take(timings, func_list)
xdata = xtick_list
ylabel = 'seconds'
xlabel = 'input size'
pt.multi_plot(
xdata, ydata_list, label_list=func_labels,
ylabel=ylabel, xlabel=xlabel,
**searchkw
)
time_result = {
'plot_timings': plot_timings,
'timings': timings,
}
return time_result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_string_monkey'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'latex'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'try_statement', 'children': ['13', '413']}, {'id': '13', 'type': 'block', 'children': ['14', '19', '24', '29', '32', '59', '92', '98', '111', '126', '151', '248', '265', '288', '305', '373', '379', '389', '411']}; {'id': '14', 'type': 'import_statement', 'children': ['15']}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pandas'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '19', 'type': 'import_statement', 'children': ['20']}; {'id': '20', 'type': 'aliased_import', 'children': ['21', '23']}, {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '24', 'type': 'import_statement', 'children': ['25']}, {'id': '25', 'type': 'aliased_import', 'children': ['26', '28']}; {'id': '26', 'type': 'dotted_name', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '29', 'type': 'import_statement', 'children': ['30']}; {'id': '30', 'type': 'dotted_name', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '44']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '41'], 'value': 'and'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}; {'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': 'arange'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '59', 'type': 'try_statement', 'children': ['60', '74']}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'call', 'children': ['65', '72']}, {'id': '65', 'type': 'attribute', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'DataFrameFormatter'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '74', 'type': 'except_clause', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'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': 'self'}; {'id': '80', 'type': 'call', 'children': ['81', '90']}, {'id': '81', 'type': 'attribute', 'children': ['82', '89']}; {'id': '82', 'type': 'attribute', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'io'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'DataFrameFormatter'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'highlight_cols'}; {'id': '98', 'type': 'function_definition', 'children': ['99', '100', '102']}, {'id': '99', 'type': 'function_name', 'children': [], 'value': 'monkey'}; {'id': '100', 'type': 'parameters', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'monkey_to_str_columns'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'latex'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'latex'}, {'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': 'ut'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'inject_func_as_method'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119', '120', '123']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'monkey'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'_to_str_columns'"}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '122', 'type': 'True', 'children': []}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '125', 'type': 'True', 'children': []}; {'id': '126', 'type': 'function_definition', 'children': ['127', '128', '130']}, {'id': '127', 'type': 'function_name', 'children': [], 'value': 'strip_ansi'}; {'id': '128', 'type': 'parameters', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '130', 'type': 'block', 'children': ['131', '134', '143']}, {'id': '131', 'type': 'import_statement', 'children': ['132']}; {'id': '132', 'type': 'dotted_name', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ansi_escape'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'string', 'children': [], 'value': "r'\\x1b[^m]*m'"}, {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ansi_escape'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': "''"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '151', 'type': 'function_definition', 'children': ['152', '153', '160']}; {'id': '152', 'type': 'function_name', 'children': [], 'value': 'justify_ansi'}, {'id': '153', 'type': 'parameters', 'children': ['154', '155', '156', '157']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'max_len'}, {'id': '157', 'type': 'default_parameter', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'right'"}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'if_statement', 'children': ['162', '165', '191', '221']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'left'"}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'list_comprehension', 'children': ['168', '188']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '+'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'max_len'}, {'id': '175', 'type': 'parenthesized_expression', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '181'], 'value': '-'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'strip_ansi'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '191', 'type': 'elif_clause', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'center'"}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'return_statement', 'children': ['197']}, {'id': '197', 'type': 'list_comprehension', 'children': ['198', '218']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '+'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'max_len'}, {'id': '205', 'type': 'parenthesized_expression', 'children': ['206']}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '211'], 'value': '-'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'strip_ansi'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '218', 'type': 'for_in_clause', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '221', 'type': 'else_clause', 'children': ['222']}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'list_comprehension', 'children': ['225', '245']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'rjust'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'max_len'}; {'id': '232', 'type': 'parenthesized_expression', 'children': ['233']}, {'id': '233', 'type': 'binary_operator', 'children': ['234', '238'], 'value': '-'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'strip_ansi'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '245', 'type': 'for_in_clause', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'inject_func_as_method'}, {'id': '253', 'type': 'argument_list', 'children': ['254', '257', '258', '259', '262']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'adj'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'justify_ansi'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'justify'"}, {'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '261', 'type': 'True', 'children': []}; {'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '264', 'type': 'True', 'children': []}, {'id': '265', 'type': 'function_definition', 'children': ['266', '267', '270']}; {'id': '266', 'type': 'function_name', 'children': [], 'value': 'strlen_ansii'}, {'id': '267', 'type': 'parameters', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '270', 'type': 'block', 'children': ['271']}, {'id': '271', 'type': 'return_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '278']}, {'id': '273', 'type': 'attribute', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'compat'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'strlen'}; {'id': '278', 'type': 'argument_list', 'children': ['279', '283']}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'strip_ansi'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'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': 'ut'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'inject_func_as_method'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '297', '298', '299', '302']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'adj'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'strlen_ansii'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'len'"}, {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '301', 'type': 'True', 'children': []}; {'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '304', 'type': 'True', 'children': []}, {'id': '305', 'type': 'if_statement', 'children': ['306', '307']}; {'id': '306', 'type': 'False', 'children': []}, {'id': '307', 'type': 'block', 'children': ['308', '320', '332', '339', '343', '347', '360', '365']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'strlen'}, {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '315', 'type': 'argument_list', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'strlen_ansii'}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'justfunc'}, {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'justify_ansi'}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'assignment', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'strcols'}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'monkey_to_str_columns'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'assignment', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'space'}; {'id': '342', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'assignment', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'lists'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'strcols'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'str_'}; {'id': '350', 'type': 'call', 'children': ['351', '356']}, {'id': '351', 'type': 'attribute', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'adj'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'adjoin'}; {'id': '356', 'type': 'argument_list', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'space'}; {'id': '358', 'type': 'list_splat', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'lists'}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'str_'}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'call', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'strip_ansi'}, {'id': '371', 'type': 'argument_list', 'children': ['372']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'str_'}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'to_string'}; {'id': '378', 'type': 'argument_list', 'children': []}, {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'assignment', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '382', 'type': 'call', 'children': ['383', '388']}, {'id': '383', 'type': 'attribute', 'children': ['384', '387']}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'buf'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '388', 'type': 'argument_list', 'children': []}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'assignment', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '392', 'type': 'call', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'list_comprehension', 'children': ['398', '403']}; {'id': '398', 'type': 'call', 'children': ['399', '402']}, {'id': '399', 'type': 'attribute', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '402', 'type': 'argument_list', 'children': []}, {'id': '403', 'type': 'for_in_clause', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '405', 'type': 'call', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '409', 'type': 'argument_list', 'children': ['410']}; {'id': '410', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '411', 'type': 'return_statement', 'children': ['412']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '413', 'type': 'except_clause', 'children': ['414', '418']}; {'id': '414', 'type': 'as_pattern', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '416', 'type': 'as_pattern_target', 'children': ['417']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '418', 'type': 'block', 'children': ['419', '440']}, {'id': '419', 'type': 'expression_statement', 'children': ['420']}; {'id': '420', 'type': 'call', 'children': ['421', '424']}, {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'printex'}; {'id': '424', 'type': 'argument_list', 'children': ['425', '434', '437']}, {'id': '425', 'type': 'call', 'children': ['426', '429']}; {'id': '426', 'type': 'attribute', 'children': ['427', '428']}, {'id': '427', 'type': 'string', 'children': [], 'value': "'pandas monkey-patch is broken: {}'"}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '429', 'type': 'argument_list', 'children': ['430']}; {'id': '430', 'type': 'call', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '432', 'type': 'argument_list', 'children': ['433']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '434', 'type': 'keyword_argument', 'children': ['435', '436']}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'tb'}; {'id': '436', 'type': 'True', 'children': []}, {'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'iswarning'}, {'id': '439', 'type': 'True', 'children': []}; {'id': '440', 'type': 'return_statement', 'children': ['441']}, {'id': '441', 'type': 'call', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '443', 'type': 'argument_list', 'children': ['444']} | def to_string_monkey(df, highlight_cols=None, latex=False):
try:
import pandas as pd
import utool as ut
import numpy as np
import six
if isinstance(highlight_cols, six.string_types) and highlight_cols == 'all':
highlight_cols = np.arange(len(df.columns))
try:
self = pd.formats.format.DataFrameFormatter(df)
except AttributeError:
self = pd.io.formats.format.DataFrameFormatter(df)
self.highlight_cols = highlight_cols
def monkey(self):
return monkey_to_str_columns(self, latex=latex)
ut.inject_func_as_method(self, monkey, '_to_str_columns', override=True, force=True)
def strip_ansi(text):
import re
ansi_escape = re.compile(r'\x1b[^m]*m')
return ansi_escape.sub('', text)
def justify_ansi(self, texts, max_len, mode='right'):
if mode == 'left':
return [x.ljust(max_len + (len(x) - len(strip_ansi(x)))) for x in texts]
elif mode == 'center':
return [x.center(max_len + (len(x) - len(strip_ansi(x)))) for x in texts]
else:
return [x.rjust(max_len + (len(x) - len(strip_ansi(x)))) for x in texts]
ut.inject_func_as_method(self.adj, justify_ansi, 'justify', override=True, force=True)
def strlen_ansii(self, text):
return pd.compat.strlen(strip_ansi(text), encoding=self.encoding)
ut.inject_func_as_method(self.adj, strlen_ansii, 'len', override=True, force=True)
if False:
strlen = ut.partial(strlen_ansii, self.adj)
justfunc = ut.partial(justify_ansi, self.adj)
strcols = monkey_to_str_columns(self)
space = 1
lists = strcols
str_ = self.adj.adjoin(space, *lists)
print(str_)
print(strip_ansi(str_))
self.to_string()
result = self.buf.getvalue()
result = '\n'.join([x.rstrip() for x in result.split('\n')])
return result
except Exception as ex:
ut.printex('pandas monkey-patch is broken: {}'.format(str(ex)),
tb=True, iswarning=True)
return str(df) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'translate'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '24', '36', '63', '120', '212']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '9', 'type': 'argument_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'BaseValidator'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Anything'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'IsA'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '45']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '42'], 'value': 'in'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'compat'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'func_types'}, {'id': '45', 'type': 'block', 'children': ['46', '52']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'real_value'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'IsA'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '60']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'real_value'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'real_value'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '69']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74', '80', '98']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '73', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'IsA'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '80', 'type': 'elif_clause', 'children': ['81', '87']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '86'], 'value': '=='}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ListOf'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'translate'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'else_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'raise_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'StructureSpecificationError'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'concatenated_string', 'children': ['107', '108']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'Expected a list containing exactly 1 item; '"}; {'id': '108', 'type': 'string', 'children': [], 'value': "'got {cnt}: {spec}'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '117']}, {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '126']}, {'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': 'value'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '126', 'type': 'block', 'children': ['127', '136', '140', '207']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '130']}; {'id': '128', 'type': 'not_operator', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'return_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'IsA'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '139', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '140', 'type': 'for_statement', 'children': ['141', '144', '149']}, {'id': '141', 'type': 'pattern_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'block', 'children': ['150', '191', '198']}; {'id': '150', 'type': 'if_statement', 'children': ['151', '156', '161']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'BaseValidator'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'k_validator'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '161', 'type': 'else_clause', 'children': ['162']}; {'id': '162', 'type': 'block', 'children': ['163', '170', '179']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'k_validator'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'translate'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'k_validator'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'get_default_for'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'if_statement', 'children': ['180', '183']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'is'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '182', 'type': 'None', 'children': []}, {'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': 'k_validator'}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'Equals'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'v_validator'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'translate'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'tuple', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'k_validator'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'v_validator'}, {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'DictOf'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '212', 'type': 'return_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'IsA'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '220']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'default'} | def translate(value):
if isinstance(value, BaseValidator):
return value
if value is None:
return Anything()
if isinstance(value, type):
return IsA(value)
if type(value) in compat.func_types:
real_value = value()
return IsA(type(real_value), default=real_value)
if isinstance(value, list):
if value == []:
return IsA(list)
elif len(value) == 1:
return ListOf(translate(value[0]))
else:
raise StructureSpecificationError(
'Expected a list containing exactly 1 item; '
'got {cnt}: {spec}'.format(cnt=len(value), spec=value))
if isinstance(value, dict):
if not value:
return IsA(dict)
items = []
for k, v in value.items():
if isinstance(k, BaseValidator):
k_validator = k
else:
k_validator = translate(k)
default = k_validator.get_default_for(None)
if default is not None:
k_validator = Equals(default)
v_validator = translate(v)
items.append((k_validator, v_validator))
return DictOf(items)
return IsA(type(value), default=value) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'with_spaces'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'with_tabs'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'with_newlines'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '20', '24', '32', '36', '321', '341']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': '"Return the parsed keys"'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'while_statement', 'children': ['37', '43']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '<'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '43', 'type': 'block', 'children': ['44', '50', '54', '292']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'augmented_assignment', 'children': ['52', '53'], 'value': '+='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '62', '99', '149', '202', '212', '222']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'MODIFIERS'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63', '69', '76', '89', '98']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'MODIFIERS'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'VirtualKeyAction'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'up'}; {'id': '88', 'type': 'False', 'children': []}, {'id': '89', 'type': 'if_statement', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"MODS+"'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '98', 'type': 'continue_statement', 'children': []}, {'id': '99', 'type': 'elif_clause', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"("'}, {'id': '103', 'type': 'block', 'children': ['104', '114', '125', '143']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'end_pos'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '")"'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '119']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'end_pos'}, {'id': '117', 'type': 'unary_operator', 'children': ['118'], 'value': '-'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'raise_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'KeySequenceError'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'`)` not found'"}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'parse_keys'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '140']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '136', 'type': 'slice', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '138', 'type': 'colon', 'children': []}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'end_pos'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'end_pos'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'elif_clause', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '=='}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"{"'}, {'id': '153', 'type': 'block', 'children': ['154', '166', '177', '186', '192']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'end_pos'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"}"'}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '171']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'end_pos'}, {'id': '169', 'type': 'unary_operator', 'children': ['170'], 'value': '-'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'raise_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'KeySequenceError'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'string', 'children': [], 'value': "'`}` not found'"}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '182', 'type': 'slice', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '184', 'type': 'colon', 'children': []}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'end_pos'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'end_pos'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'keys'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'handle_code'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '202', 'type': 'elif_clause', 'children': ['203', '206']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '205', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'raise_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'KeySequenceError'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'string', 'children': [], 'value': "'`)` should be preceeded by `(`'"}; {'id': '212', 'type': 'elif_clause', 'children': ['213', '216']}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '=='}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'}'"}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'raise_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'KeySequenceError'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'`}` should be preceeded by `{`'"}; {'id': '222', 'type': 'else_clause', 'children': ['223']}, {'id': '223', 'type': 'block', 'children': ['224', '248']}; {'id': '224', 'type': 'if_statement', 'children': ['225', '246']}, {'id': '225', 'type': 'parenthesized_expression', 'children': ['226']}; {'id': '226', 'type': 'boolean_operator', 'children': ['227', '240'], 'value': 'or'}, {'id': '227', 'type': 'boolean_operator', 'children': ['228', '234'], 'value': 'or'}; {'id': '228', 'type': 'boolean_operator', 'children': ['229', '232'], 'value': 'and'}, {'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '=='}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '231', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '232', 'type': 'not_operator', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'with_spaces'}; {'id': '234', 'type': 'boolean_operator', 'children': ['235', '238'], 'value': 'and'}, {'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': '=='}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '237', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '238', 'type': 'not_operator', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'with_tabs'}; {'id': '240', 'type': 'boolean_operator', 'children': ['241', '244'], 'value': 'and'}, {'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '243', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '244', 'type': 'not_operator', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'with_newlines'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'continue_statement', 'children': []}; {'id': '248', 'type': 'if_statement', 'children': ['249', '254', '267', '280']}, {'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': 'in'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '251', 'type': 'tuple', 'children': ['252', '253']}; {'id': '252', 'type': 'string', 'children': [], 'value': "'~'"}, {'id': '253', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '254', 'type': 'block', 'children': ['255']}, {'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': 'keys'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'VirtualKeyAction'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'CODES'}; {'id': '266', 'type': 'string', 'children': [], 'value': '"ENTER"'}, {'id': '267', 'type': 'elif_clause', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '269', 'type': 'block', 'children': ['270']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'EscapedKeyAction'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '280', 'type': 'else_clause', 'children': ['281']}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'KeyAction'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '292', 'type': 'while_statement', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '294', 'type': 'block', 'children': ['295', '304']}, {'id': '295', 'type': 'if_statement', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}, {'id': '297', 'type': 'block', 'children': ['298']}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '301', 'type': 'argument_list', 'children': ['302', '303']}; {'id': '302', 'type': 'string', 'children': [], 'value': '"MODS-"'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'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': 'keys'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'VirtualKeyAction'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '318']}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '317', 'type': 'argument_list', 'children': []}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'down'}; {'id': '320', 'type': 'False', 'children': []}, {'id': '321', 'type': 'while_statement', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'modifiers'}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'VirtualKeyAction'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '338']}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'modifiers'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '337', 'type': 'argument_list', 'children': []}; {'id': '338', 'type': 'keyword_argument', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'down'}; {'id': '340', 'type': 'False', 'children': []}, {'id': '341', 'type': 'return_statement', 'children': ['342']} | def parse_keys(string,
with_spaces = False,
with_tabs = False,
with_newlines = False,
modifiers = None):
"Return the parsed keys"
keys = []
if not modifiers:
modifiers = []
index = 0
while index < len(string):
c = string[index]
index += 1
if c in MODIFIERS.keys():
modifier = MODIFIERS[c]
modifiers.append(modifier)
keys.append(VirtualKeyAction(modifier, up = False))
if DEBUG:
print("MODS+", modifiers)
continue
elif c == "(":
end_pos = string.find(")", index)
if end_pos == -1:
raise KeySequenceError('`)` not found')
keys.extend(
parse_keys(string[index:end_pos], modifiers = modifiers))
index = end_pos + 1
elif c == "{":
end_pos = string.find("}", index + 1)
if end_pos == -1:
raise KeySequenceError('`}` not found')
code = string[index:end_pos]
index = end_pos + 1
keys.extend(handle_code(code))
elif c == ')':
raise KeySequenceError('`)` should be preceeded by `(`')
elif c == '}':
raise KeySequenceError('`}` should be preceeded by `{`')
else:
if (c == ' ' and not with_spaces or
c == '\t' and not with_tabs or
c == '\n' and not with_newlines):
continue
if c in ('~', '\n'):
keys.append(VirtualKeyAction(CODES["ENTER"]))
elif modifiers:
keys.append(EscapedKeyAction(c))
else:
keys.append(KeyAction(c))
while modifiers:
if DEBUG:
print("MODS-", modifiers)
keys.append(VirtualKeyAction(modifiers.pop(), down = False))
while modifiers:
keys.append(VirtualKeyAction(modifiers.pop(), down = False))
return keys |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_argflag'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'argstr_'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'help_'}; {'id': '10', 'type': 'string', 'children': [], 'value': "''"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'return_specified'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'need_prefix'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'return_was_specified'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'block', 'children': ['29', '40', '47', '56', '64', '68', '72', '81', '84', '85', '197', '336', '345']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '40', 'type': 'assert_statement', 'children': ['41', '46']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'default must be boolean'"}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'argstr_list'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'meta_util_iter'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ensure_iterable'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'argstr_'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_register_arg'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62', '63']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'argstr_list'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'help_'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'was_specified'}, {'id': '71', 'type': 'False', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '75', 'type': 'None', 'children': []}; {'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': 'debug'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}, {'id': '81', 'type': 'import_statement', 'children': ['82']}; {'id': '82', 'type': 'dotted_name', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '84', 'type': 'comment', 'children': []}, {'id': '85', 'type': 'for_statement', 'children': ['86', '89', '96']}; {'id': '86', 'type': 'pattern_list', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97', '105', '109']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sentinal'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'UTOOL_'"}, {'id': '109', 'type': 'if_statement', 'children': ['110', '116']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sentinal'}; {'id': '116', 'type': 'block', 'children': ['117', '140', '167', '172', '181']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'--'"}; {'id': '122', 'type': 'call', 'children': ['123', '137']}, {'id': '123', 'type': 'attribute', 'children': ['124', '136']}; {'id': '124', 'type': 'call', 'children': ['125', '135']}, {'id': '125', 'type': 'attribute', 'children': ['126', '134']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'slice', 'children': ['129', '133']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sentinal'}, {'id': '133', 'type': 'colon', 'children': []}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '139', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '140', 'type': 'if_statement', 'children': ['141', '150', '152', '164']}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '147'], 'value': 'in'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '146', 'type': 'argument_list', 'children': []}, {'id': '147', 'type': 'list', 'children': ['148', '149'], 'value': "['TRUE', 'ON']"}; {'id': '148', 'type': 'string', 'children': [], 'value': "'TRUE'"}, {'id': '149', 'type': 'string', 'children': [], 'value': "'ON'"}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'pass_statement', 'children': []}; {'id': '152', 'type': 'elif_clause', 'children': ['153', '162']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '159'], 'value': 'in'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'list', 'children': ['160', '161'], 'value': "['FALSE', 'OFF']"}; {'id': '160', 'type': 'string', 'children': [], 'value': "'FALSE'"}, {'id': '161', 'type': 'string', 'children': [], 'value': "'OFF'"}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'continue_statement', 'children': []}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'continue_statement', 'children': []}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'new_argv'}; {'id': '170', 'type': 'list', 'children': ['171'], 'value': '[flag]'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '180'], 'value': '+'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '178', 'type': 'slice', 'children': ['179']}, {'id': '179', 'type': 'colon', 'children': []}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'new_argv'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '183', 'type': 'block', 'children': ['184', '189']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'ENV SPECIFIED COMMAND LINE'"}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '%'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'argv.extend(new_argv=%r)'"}, {'id': '195', 'type': 'tuple', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'new_argv'}, {'id': '197', 'type': 'for_statement', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'argstr'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'argstr_list'}; {'id': '200', 'type': 'block', 'children': ['201', '238', '266', '276']}, {'id': '201', 'type': 'if_statement', 'children': ['202', '229']}; {'id': '202', 'type': 'not_operator', 'children': ['203']}, {'id': '203', 'type': 'parenthesized_expression', 'children': ['204']}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '213'], 'value': 'or'}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '212'], 'value': '=='}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'argstr'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'string', 'children': [], 'value': "'--'"}; {'id': '212', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '213', 'type': 'parenthesized_expression', 'children': ['214']}; {'id': '214', 'type': 'boolean_operator', 'children': ['215', '223'], 'value': 'and'}, {'id': '215', 'type': 'comparison_operator', 'children': ['216', '222'], 'value': '=='}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'argstr'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '222', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '228'], 'value': '=='}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'raise_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '%'}, {'id': '235', 'type': 'string', 'children': [], 'value': "'Invalid argstr: %r'"}; {'id': '236', 'type': 'tuple', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '238', 'type': 'if_statement', 'children': ['239', '241']}, {'id': '239', 'type': 'not_operator', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'need_prefix'}, {'id': '241', 'type': 'block', 'children': ['242', '252']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'noprefix'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'--'"}, {'id': '251', 'type': 'string', 'children': [], 'value': "''"}; {'id': '252', 'type': 'if_statement', 'children': ['253', '256']}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': 'in'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'noprefix'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '256', 'type': 'block', 'children': ['257', '261', '265']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}; {'id': '260', 'type': 'True', 'children': []}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '264', 'type': 'True', 'children': []}, {'id': '265', 'type': 'break_statement', 'children': []}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'noarg'}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '273', 'type': 'argument_list', 'children': ['274', '275']}; {'id': '274', 'type': 'string', 'children': [], 'value': "'--'"}, {'id': '275', 'type': 'string', 'children': [], 'value': "'--no'"}; {'id': '276', 'type': 'if_statement', 'children': ['277', '280', '290', '304', '320']}, {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': 'in'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'argstr'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '280', 'type': 'block', 'children': ['281', '285', '289']}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}; {'id': '284', 'type': 'True', 'children': []}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '288', 'type': 'True', 'children': []}, {'id': '289', 'type': 'break_statement', 'children': []}; {'id': '290', 'type': 'elif_clause', 'children': ['291', '294']}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': 'in'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'noarg'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '294', 'type': 'block', 'children': ['295', '299', '303']}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}; {'id': '298', 'type': 'False', 'children': []}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '302', 'type': 'True', 'children': []}, {'id': '303', 'type': 'break_statement', 'children': []}; {'id': '304', 'type': 'elif_clause', 'children': ['305', '310']}, {'id': '305', 'type': 'comparison_operator', 'children': ['306', '309'], 'value': 'in'}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '+'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'=True'"}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '310', 'type': 'block', 'children': ['311', '315', '319']}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}; {'id': '314', 'type': 'True', 'children': []}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '318', 'type': 'True', 'children': []}, {'id': '319', 'type': 'break_statement', 'children': []}; {'id': '320', 'type': 'elif_clause', 'children': ['321', '326']}, {'id': '321', 'type': 'comparison_operator', 'children': ['322', '325'], 'value': 'in'}; {'id': '322', 'type': 'binary_operator', 'children': ['323', '324'], 'value': '+'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'argstr'}; {'id': '324', 'type': 'string', 'children': [], 'value': "'=False'"}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '326', 'type': 'block', 'children': ['327', '331', '335']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}; {'id': '330', 'type': 'False', 'children': []}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '334', 'type': 'True', 'children': []}, {'id': '335', 'type': 'break_statement', 'children': []}; {'id': '336', 'type': 'if_statement', 'children': ['337', '340']}, {'id': '337', 'type': 'comparison_operator', 'children': ['338', '339'], 'value': 'is'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'return_specified'}, {'id': '339', 'type': 'None', 'children': []}; {'id': '340', 'type': 'block', 'children': ['341']}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'assignment', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'return_specified'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'return_was_specified'}, {'id': '345', 'type': 'if_statement', 'children': ['346', '347', '352']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'return_specified'}, {'id': '347', 'type': 'block', 'children': ['348']}; {'id': '348', 'type': 'return_statement', 'children': ['349']}, {'id': '349', 'type': 'expression_list', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'parsed_val'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'was_specified'}; {'id': '352', 'type': 'else_clause', 'children': ['353']}, {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'return_statement', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'parsed_val'} | def get_argflag(argstr_, default=False, help_='', return_specified=None,
need_prefix=True, return_was_specified=False, argv=None,
debug=None,
**kwargs):
if argv is None:
argv = sys.argv
assert isinstance(default, bool), 'default must be boolean'
argstr_list = meta_util_iter.ensure_iterable(argstr_)
_register_arg(argstr_list, bool, default, help_)
parsed_val = default
was_specified = False
if debug is None:
debug = DEBUG
import os
#
for key, val in os.environ.items():
key = key.upper()
sentinal = 'UTOOL_'
if key.startswith(sentinal):
flag = '--' + key[len(sentinal):].lower().replace('_', '-')
if val.upper() in ['TRUE', 'ON']:
pass
elif val.upper() in ['FALSE', 'OFF']:
continue
else:
continue
new_argv = [flag]
argv = argv[:] + new_argv
if debug:
print('ENV SPECIFIED COMMAND LINE')
print('argv.extend(new_argv=%r)' % (new_argv,))
for argstr in argstr_list:
if not (argstr.find('--') == 0 or (argstr.find('-') == 0 and len(argstr) == 2)):
raise AssertionError('Invalid argstr: %r' % (argstr,))
if not need_prefix:
noprefix = argstr.replace('--', '')
if noprefix in argv:
parsed_val = True
was_specified = True
break
noarg = argstr.replace('--', '--no')
if argstr in argv:
parsed_val = True
was_specified = True
break
elif noarg in argv:
parsed_val = False
was_specified = True
break
elif argstr + '=True' in argv:
parsed_val = True
was_specified = True
break
elif argstr + '=False' in argv:
parsed_val = False
was_specified = True
break
if return_specified is None:
return_specified = return_was_specified
if return_specified:
return parsed_val, was_specified
else:
return parsed_val |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_arg_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '11']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'prefix_list'}, {'id': '9', 'type': 'list', 'children': ['10'], 'value': "['--']"}; {'id': '10', 'type': 'string', 'children': [], 'value': "'--'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'type_hints'}, {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '17', '28', '32', '51', '96', '167', '265']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '20', 'type': 'None', 'children': []}, {'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': 'argv'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'arg_dict'}, {'id': '31', 'type': 'dictionary', 'children': []}; {'id': '32', 'type': 'function_definition', 'children': ['33', '34', '36']}, {'id': '33', 'type': 'function_name', 'children': [], 'value': 'startswith_prefix'}; {'id': '34', 'type': 'parameters', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'list_comprehension', 'children': ['42', '48']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'prefix_list'}, {'id': '51', 'type': 'function_definition', 'children': ['52', '53', '56']}; {'id': '52', 'type': 'function_name', 'children': [], 'value': 'argx_has_value'}, {'id': '53', 'type': 'parameters', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '56', 'type': 'block', 'children': ['57', '72', '94']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '69']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '67'], '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': 'argv'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '67', 'type': 'unary_operator', 'children': ['68'], 'value': '-'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '91']}, {'id': '73', 'type': 'boolean_operator', 'children': ['74', '82'], 'value': 'and'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '<'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'argx'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'startswith_prefix'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'id': '93', 'type': 'True', 'children': []}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'False', 'children': []}; {'id': '96', 'type': 'function_definition', 'children': ['97', '98', '102']}, {'id': '97', 'type': 'function_name', 'children': [], 'value': 'get_arg_value'}; {'id': '98', 'type': 'parameters', 'children': ['99', '100', '101']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'argx'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'argname'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'if_statement', 'children': ['104', '115', '134']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '113'], 'value': '>'}, {'id': '105', 'type': 'call', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '113', 'type': 'unary_operator', 'children': ['114'], 'value': '-'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'='"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'subscript', 'children': ['123', '131']}, {'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': 'argv'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '131', 'type': 'slice', 'children': ['132', '133']}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '133', 'type': 'colon', 'children': []}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136', '146']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'type_hints'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'argname'}, {'id': '145', 'type': 'None', 'children': []}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150', '157']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '+'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'return_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'parse_arglist_hack'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '167', 'type': 'for_statement', 'children': ['168', '169', '176']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'argx'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '176', 'type': 'block', 'children': ['177', '183']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'argx'}, {'id': '183', 'type': 'for_statement', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'prefix_list'}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'if_statement', 'children': ['188', '194']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '194', 'type': 'block', 'children': ['195', '206', '264']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'argname'}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '200', 'type': 'slice', 'children': ['201', '205']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '205', 'type': 'colon', 'children': []}; {'id': '206', 'type': 'if_statement', 'children': ['207', '212', '256']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'argx_has_value'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'argx'}; {'id': '212', 'type': 'block', 'children': ['213', '241', '250']}, {'id': '213', 'type': 'if_statement', 'children': ['214', '223']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '221'], 'value': '>'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '221', 'type': 'unary_operator', 'children': ['222'], 'value': '-'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'argname'}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '229', 'type': 'slice', 'children': ['230', '234', '235']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '234', 'type': 'colon', 'children': []}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'argvalue'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'get_arg_value'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248', '249']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'argx'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'argname'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'arg_dict'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'argname'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'argvalue'}; {'id': '256', 'type': 'else_clause', 'children': ['257']}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '263']}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'arg_dict'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'argname'}, {'id': '263', 'type': 'True', 'children': []}; {'id': '264', 'type': 'break_statement', 'children': []}, {'id': '265', 'type': 'return_statement', 'children': ['266']} | def get_arg_dict(argv=None, prefix_list=['--'], type_hints={}):
r
if argv is None:
argv = sys.argv
arg_dict = {}
def startswith_prefix(arg):
return any([arg.startswith(prefix) for prefix in prefix_list])
def argx_has_value(argv, argx):
if argv[argx].find('=') > -1:
return True
if argx + 1 < len(argv) and not startswith_prefix(argv[argx + 1]):
return True
return False
def get_arg_value(argv, argx, argname):
if argv[argx].find('=') > -1:
return '='.join(argv[argx].split('=')[1:])
else:
type_ = type_hints.get(argname, None)
if type_ is None:
return argv[argx + 1]
else:
return parse_arglist_hack(argx, argv=argv)
for argx in range(len(argv)):
arg = argv[argx]
for prefix in prefix_list:
if arg.startswith(prefix):
argname = arg[len(prefix):]
if argx_has_value(argv, argx):
if arg.find('=') > -1:
argname = arg[len(prefix):arg.find('=')]
argvalue = get_arg_value(argv, argx, argname)
arg_dict[argname] = argvalue
else:
arg_dict[argname] = True
break
return arg_dict |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__argv_flag_dec'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'QUIET'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '20', '29', '47', '63', '261', '274']}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'util_decor'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'flagname'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '38']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '37'], 'value': '=='}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'flagname'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'no'"}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'flagname'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'flagname'}; {'id': '44', 'type': 'slice', 'children': ['45', '46']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '46', 'type': 'colon', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '50', 'type': 'tuple', 'children': ['51', '60']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'--'"}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'flagname'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '59', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'--'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'flagname'}, {'id': '63', 'type': 'decorated_definition', 'children': ['64', '73']}; {'id': '64', 'type': 'decorator', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'util_decor'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'ignores_exc_tb'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'outer_wrapper'}; {'id': '72', 'type': 'False', 'children': []}, {'id': '73', 'type': 'function_definition', 'children': ['74', '75', '80']}; {'id': '74', 'type': 'function_name', 'children': [], 'value': 'GaurdWrapper'}, {'id': '75', 'type': 'parameters', 'children': ['76', '78']}; {'id': '76', 'type': 'list_splat_pattern', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '78', 'type': 'dictionary_splat_pattern', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '80', 'type': 'block', 'children': ['81', '86', '96', '106', '132', '146']}, {'id': '81', 'type': 'import_from_statement', 'children': ['82', '84']}; {'id': '82', 'type': 'dotted_name', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '84', 'type': 'dotted_name', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'util_print'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'default_'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'default'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'alias_flags'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': "'alias_flags'"}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'is_flagged'}, {'id': '109', 'type': 'parenthesized_expression', 'children': ['110']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '121'], 'value': 'or'}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '117'], 'value': 'or'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'default_'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'--print-all'"}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'list_comprehension', 'children': ['125', '129']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'alias_flags'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'flagname'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': 'is_flagged'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'flagname'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '148', '233']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'is_flagged'}; {'id': '148', 'type': 'block', 'children': ['149', '167', '176', '182', '199', '222', '231']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'func_label'}; {'id': '152', 'type': 'call', 'children': ['153', '164']}, {'id': '153', 'type': 'attribute', 'children': ['154', '163']}; {'id': '154', 'type': 'call', 'children': ['155', '160']}, {'id': '155', 'type': 'attribute', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}, {'id': '161', 'type': 'string', 'children': [], 'value': "'--'"}; {'id': '162', 'type': 'string', 'children': [], 'value': "''"}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'print-'"}; {'id': '166', 'type': 'string', 'children': [], 'value': "''"}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '+'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'\\n+ --- '"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'func_label'}, {'id': '175', 'type': 'string', 'children': [], 'value': "' ___'"}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'use_indent'}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'is'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '181', 'type': 'False', 'children': []}; {'id': '182', 'type': 'if_statement', 'children': ['183', '186', '193']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'is'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '185', 'type': 'True', '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': 'indent_'}; {'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '%'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'[%s]'"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'func_label'}, {'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': 'indent_'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '199', 'type': 'with_statement', 'children': ['200', '211']}; {'id': '200', 'type': 'with_clause', 'children': ['201']}, {'id': '201', 'type': 'with_item', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'util_print'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'Indenter'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'indent_'}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'enabled'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'use_indent'}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '220']}; {'id': '218', 'type': 'list_splat', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '220', 'type': 'dictionary_splat', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '+'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'L ___ '"}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'func_label'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'___\\n'"}, {'id': '231', 'type': 'return_statement', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '233', 'type': 'else_clause', 'children': ['234']}; {'id': '234', 'type': 'block', 'children': ['235', '246']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'PRINT_DISABLED_FLAGDEC'}; {'id': '238', 'type': 'not_operator', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'--noinform'"}, {'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'help_'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'does not print disabled flag decorators'"}; {'id': '246', 'type': 'if_statement', 'children': ['247', '251']}, {'id': '247', 'type': 'boolean_operator', 'children': ['248', '250'], 'value': 'and'}; {'id': '248', 'type': 'not_operator', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'PRINT_DISABLED_FLAGDEC'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '%'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'~~~ %s ~~~'"}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'set_funcname'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'GaurdWrapper'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '274', 'type': 'return_statement', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'GaurdWrapper'} | def __argv_flag_dec(func, default=False, quiet=QUIET, indent=False):
from utool import util_decor
flagname = meta_util_six.get_funcname(func)
if flagname.find('no') == 0:
flagname = flagname[2:]
flags = (
'--' + flagname.replace('_', '-'),
'--' + flagname,
)
@util_decor.ignores_exc_tb(outer_wrapper=False)
def GaurdWrapper(*args, **kwargs):
from utool import util_print
default_ = kwargs.pop('default', default)
alias_flags = kwargs.pop('alias_flags', [])
is_flagged = (get_argflag(flags, default_) or
get_argflag('--print-all') or
any([get_argflag(_) for _ in alias_flags]))
if flagname in kwargs:
is_flagged = kwargs.pop(flagname)
if is_flagged:
func_label = flags[0].replace('--', '').replace('print-', '')
print('\n+ --- ' + func_label + ' ___')
use_indent = indent is not False
if indent is True:
indent_ = '[%s]' % func_label
else:
indent_ = indent
with util_print.Indenter(indent_, enabled=use_indent):
ret = func(*args, **kwargs)
print('L ___ ' + func_label + '___\n')
return ret
else:
PRINT_DISABLED_FLAGDEC = not get_argflag(
'--noinform', help_='does not print disabled flag decorators')
if not quiet and PRINT_DISABLED_FLAGDEC:
print('~~~ %s ~~~' % flags[0])
meta_util_six.set_funcname(GaurdWrapper, meta_util_six.get_funcname(func))
return GaurdWrapper |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'include_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'include_dirs'}; {'id': '8', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '9', 'type': 'block', 'children': ['10']}; {'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': 'include_includes'}; {'id': '14', 'type': 'block', 'children': ['15', '27', '36', '47', '178', '184']}, {'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': 'debug'}, {'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': 'print'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'}, {'id': '25', 'type': 'string', 'children': [], 'value': '"------------------ Including a file: %s"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'inc_dirs'}; {'id': '30', 'type': 'conditional_expression', 'children': ['31', '32', '33'], 'value': 'if'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'include_dirs'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'include_dirs'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'include_dirs'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'LEMSFileParser'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'inc_dirs'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'include_includes'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '57', '105']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'access'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'F_OK'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '65', '90']}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'included_files'}, {'id': '65', 'type': 'block', 'children': ['66', '80', '89']}; {'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': 'parser'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '79']}, {'id': '73', 'type': 'attribute', 'children': ['74', '78']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'included_files'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '89', 'type': 'return_statement', 'children': []}; {'id': '90', 'type': 'else_clause', 'children': ['91']}, {'id': '91', 'type': 'block', 'children': ['92', '104']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"Already included: %s"'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '104', 'type': 'return_statement', 'children': []}, {'id': '105', 'type': 'else_clause', 'children': ['106']}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'inc_dir'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'inc_dirs'}; {'id': '110', 'type': 'block', 'children': ['111', '120']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'new_path'}; {'id': '114', 'type': 'parenthesized_expression', 'children': ['115']}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '119'], 'value': '+'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '+'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'inc_dir'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '130']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'access'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_path'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'F_OK'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'if_statement', 'children': ['132', '138', '163']}; {'id': '132', 'type': 'not_operator', 'children': ['133']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'new_path'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'included_files'}; {'id': '138', 'type': 'block', 'children': ['139', '153', '162']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '152']}; {'id': '146', 'type': 'attribute', 'children': ['147', '151']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'new_path'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '152', 'type': 'argument_list', 'children': []}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '160']}, {'id': '155', 'type': 'attribute', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'included_files'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'new_path'}; {'id': '162', 'type': 'return_statement', 'children': []}, {'id': '163', 'type': 'else_clause', 'children': ['164']}; {'id': '164', 'type': 'block', 'children': ['165', '177']}, {'id': '165', 'type': 'if_statement', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'}, {'id': '175', 'type': 'string', 'children': [], 'value': '"Already included: %s"'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '177', 'type': 'return_statement', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '+'}; {'id': '182', 'type': 'string', 'children': [], 'value': "'Unable to open '"}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188', '194']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fail_on_missing_includes'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'raise_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '194', 'type': 'elif_clause', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'msg'} | def include_file(self, path, include_dirs = []):
if self.include_includes:
if self.debug: print("------------------ Including a file: %s"%path)
inc_dirs = include_dirs if include_dirs else self.include_dirs
parser = LEMSFileParser(self, inc_dirs, self.include_includes)
if os.access(path, os.F_OK):
if not path in self.included_files:
parser.parse(open(path).read())
self.included_files.append(path)
return
else:
if self.debug: print("Already included: %s"%path)
return
else:
for inc_dir in inc_dirs:
new_path = (inc_dir + '/' + path)
if os.access(new_path, os.F_OK):
if not new_path in self.included_files:
parser.parse(open(new_path).read())
self.included_files.append(new_path)
return
else:
if self.debug: print("Already included: %s"%path)
return
msg = 'Unable to open ' + path
if self.fail_on_missing_includes:
raise Exception(msg)
elif self.debug:
print(msg) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_simulation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ct'}, {'id': '7', 'type': 'block', 'children': ['8', '73', '193', '257', '337']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '10', '15']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ct'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'runs'}, {'id': '15', 'type': 'block', 'children': ['16', '64']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '54']}, {'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': 'run2'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Run'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '33', '36', '45']}; {'id': '24', 'type': 'attribute', 'children': ['25', '32']}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'component_references'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'referenced_component'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '36', 'type': 'attribute', 'children': ['37', '44']}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'increment'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'numeric_value'}, {'id': '45', 'type': 'attribute', 'children': ['46', '53']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'total'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'numeric_value'}; {'id': '54', 'type': 'except_clause', 'children': ['55']}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'raise_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ModelError'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation run parameters in component \'{0}\'"'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'run2'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '80']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '80', 'type': 'block', 'children': ['81', '184']}, {'id': '81', 'type': 'try_statement', 'children': ['82', '149', '174']}; {'id': '82', 'type': 'ERROR', 'children': ['83', '147', '148']}, {'id': '83', 'type': 'ERROR', 'children': ['84', '85', '86', '95', '109']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'record2'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Record'}; {'id': '86', 'type': 'attribute', 'children': ['87', '94']}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'quantity'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '95', 'type': 'conditional_expression', 'children': ['96', '105', '108'], 'value': 'if'}; {'id': '96', 'type': 'attribute', 'children': ['97', '104']}, {'id': '97', 'type': 'subscript', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'scale'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'numeric_value'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'scale'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'conditional_expression', 'children': ['110', '119', '122', '140'], 'value': 'if'}; {'id': '110', 'type': 'attribute', 'children': ['111', '118']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '122', 'type': 'ERROR', 'children': ['123', '139']}, {'id': '123', 'type': 'call', 'children': ['124', '137']}; {'id': '124', 'type': 'attribute', 'children': ['125', '136']}, {'id': '125', 'type': 'attribute', 'children': ['126', '133', '135']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'ModelError'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation record parameters in component \'{0}\'"'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '133', 'type': 'ERROR', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'record2'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'event_record'}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ct'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'event_records'}, {'id': '147', 'type': 'block', 'children': [], 'value': ''}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'try'}, {'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': 'event_record2'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'EventRecord'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '165']}; {'id': '156', 'type': 'attribute', 'children': ['157', '164']}, {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'event_record'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'quantity'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '165', 'type': 'attribute', 'children': ['166', '173']}; {'id': '166', 'type': 'subscript', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'event_record'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'eventPort'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '174', 'type': 'except_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'raise_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ModelError'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation event_record parameters in component \'{0}\'"'}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'event_record2'}, {'id': '193', 'type': 'for_statement', 'children': ['194', '195', '200']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'dd'}, {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'data_displays'}; {'id': '200', 'type': 'block', 'children': ['201', '248']}, {'id': '201', 'type': 'try_statement', 'children': ['202', '238']}; {'id': '202', 'type': 'block', 'children': ['203', '219']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'dd2'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'DataDisplay'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '218']}, {'id': '209', 'type': 'attribute', 'children': ['210', '217']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'dd'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '218', 'type': 'string', 'children': [], 'value': "''"}, {'id': '219', 'type': 'if_statement', 'children': ['220', '225']}; {'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'in'}, {'id': '221', 'type': 'string', 'children': [], 'value': "'timeScale'"}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'dd2'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'timeScale'}, {'id': '231', 'type': 'attribute', 'children': ['232', '237']}; {'id': '232', 'type': 'subscript', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'timeScale'"}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'numeric_value'}; {'id': '238', 'type': 'except_clause', 'children': ['239']}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'raise_statement', 'children': ['241']}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ModelError'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation display parameters in component \'{0}\'"'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '255']}; {'id': '250', 'type': 'attribute', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'dd2'}, {'id': '257', 'type': 'for_statement', 'children': ['258', '259', '264']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'dw'}, {'id': '259', 'type': 'attribute', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'data_writers'}; {'id': '264', 'type': 'block', 'children': ['265', '328']}, {'id': '265', 'type': 'try_statement', 'children': ['266', '318']}; {'id': '266', 'type': 'block', 'children': ['267', '271', '302']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '271', 'type': 'if_statement', 'children': ['272', '289']}; {'id': '272', 'type': 'boolean_operator', 'children': ['273', '280'], 'value': 'and'}, {'id': '273', 'type': 'subscript', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'dw'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '280', 'type': 'attribute', 'children': ['281', '288']}, {'id': '281', 'type': 'subscript', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'dw'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '293', 'type': 'attribute', 'children': ['294', '301']}; {'id': '294', 'type': 'subscript', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'dw'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'dw2'}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'DataWriter'}, {'id': '307', 'type': 'argument_list', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '309', 'type': 'attribute', 'children': ['310', '317']}; {'id': '310', 'type': 'subscript', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'dw'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'file_name'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '318', 'type': 'except_clause', 'children': ['319']}, {'id': '319', 'type': 'block', 'children': ['320']}; {'id': '320', 'type': 'raise_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'ModelError'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation writer parameters in component \'{0}\'"'}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'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': 'fc'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'simulation'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'dw2'}, {'id': '337', 'type': 'for_statement', 'children': ['338', '339', '344']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'ew'}, {'id': '339', 'type': 'attribute', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'event_writers'}; {'id': '344', 'type': 'block', 'children': ['345', '417']}, {'id': '345', 'type': 'try_statement', 'children': ['346', '407']}; {'id': '346', 'type': 'block', 'children': ['347', '351', '382']}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '350', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '351', 'type': 'if_statement', 'children': ['352', '369']}; {'id': '352', 'type': 'boolean_operator', 'children': ['353', '360'], 'value': 'and'}, {'id': '353', 'type': 'subscript', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'ew'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '360', 'type': 'attribute', 'children': ['361', '368']}, {'id': '361', 'type': 'subscript', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'ew'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'value'}, {'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': 'path'}, {'id': '373', 'type': 'attribute', 'children': ['374', '381']}; {'id': '374', 'type': 'subscript', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'ew'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'assignment', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'ew2'}, {'id': '385', 'type': 'call', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'EventWriter'}, {'id': '387', 'type': 'argument_list', 'children': ['388', '389', '398']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '389', 'type': 'attribute', 'children': ['390', '397']}; {'id': '390', 'type': 'subscript', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'fc'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'texts'}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'ew'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'file_name'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '398', 'type': 'attribute', 'children': ['399', '406']}, {'id': '399', 'type': 'subscript', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'texts'}, {'id': '403', 'type': 'attribute', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'ew'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '407', 'type': 'except_clause', 'children': ['408']}; {'id': '408', 'type': 'block', 'children': ['409']}, {'id': '409', 'type': 'raise_statement', 'children': ['410']}; {'id': '410', 'type': 'call', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'ModelError'}; {'id': '412', 'type': 'argument_list', 'children': ['413', '414']}, {'id': '413', 'type': 'string', 'children': [], 'value': '"Unable to resolve simulation writer parameters in component \'{0}\'"'}; {'id': '414', 'type': 'attribute', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '417', 'type': 'expression_statement', 'children': ['418']}; {'id': '418', 'type': 'call', 'children': ['419', '424']}, {'id': '419', 'type': 'attribute', 'children': ['420', '423']}; {'id': '420', 'type': 'attribute', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'fc'}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'simulation'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '424', 'type': 'argument_list', 'children': ['425']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'ew2'} | def resolve_simulation(self, fc, ct):
for run in ct.simulation.runs:
try:
run2 = Run(fc.component_references[run.component].referenced_component,
run.variable,
fc.parameters[run.increment].numeric_value,
fc.parameters[run.total].numeric_value)
except:
raise ModelError("Unable to resolve simulation run parameters in component '{0}'",
fc.id)
fc.simulation.add(run2)
for record in ct.simulation.records:
try:
record2 = Record(fc.paths[record.quantity].value,
fc.parameters[record.scale].numeric_value if record.scale else 1,
fc.texts[record.color].value if record.color else '
except:
raise ModelError("Unable to resolve simulation record parameters in component '{0}'",
fc.id)
fc.simulation.add(record2)
for event_record in ct.simulation.event_records:
try:
event_record2 = EventRecord(fc.paths[event_record.quantity].value,
fc.texts[event_record.eventPort].value)
except:
raise ModelError("Unable to resolve simulation event_record parameters in component '{0}'",
fc.id)
fc.simulation.add(event_record2)
for dd in ct.simulation.data_displays:
try:
dd2 = DataDisplay(fc.texts[dd.title].value,
'')
if 'timeScale' in fc.parameters:
dd2.timeScale = fc.parameters['timeScale'].numeric_value
except:
raise ModelError("Unable to resolve simulation display parameters in component '{0}'",
fc.id)
fc.simulation.add(dd2)
for dw in ct.simulation.data_writers:
try:
path = '.'
if fc.texts[dw.path] and fc.texts[dw.path].value:
path = fc.texts[dw.path].value
dw2 = DataWriter(path,
fc.texts[dw.file_name].value)
except:
raise ModelError("Unable to resolve simulation writer parameters in component '{0}'",
fc.id)
fc.simulation.add(dw2)
for ew in ct.simulation.event_writers:
try:
path = '.'
if fc.texts[ew.path] and fc.texts[ew.path].value:
path = fc.texts[ew.path].value
ew2 = EventWriter(path,
fc.texts[ew.file_name].value,
fc.texts[ew.format].value)
except:
raise ModelError("Unable to resolve simulation writer parameters in component '{0}'",
fc.id)
fc.simulation.add(ew2) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_derived_parameters'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '5', 'type': 'block', 'children': ['6', '18', '22', '26', '41', '45', '49', '124', '142']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '15']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '14'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'derived_parameters'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dps'}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '31']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dp'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'derived_parameters'}, {'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': 'dps'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dp'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'maxcount'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'maxcount'}, {'id': '49', 'type': 'while_statement', 'children': ['50', '57']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'and'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '>'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '!='}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dps'}; {'id': '56', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '57', 'type': 'block', 'children': ['58', '64']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '-'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dp1'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dps'}, {'id': '67', 'type': 'block', 'children': ['68', '78', '82', '99']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '71', 'type': 'attribute', 'children': ['72', '77']}; {'id': '72', 'type': 'subscript', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'derived_parameters'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dp1'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '81', 'type': 'False', 'children': []}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dp2'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dps'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '94']}, {'id': '87', 'type': 'boolean_operator', 'children': ['88', '91'], 'value': 'and'}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '!='}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dp1'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dp2'}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dp2'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '98', 'type': 'True', 'children': []}, {'id': '99', 'type': 'if_statement', 'children': ['100', '102']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '102', 'type': 'block', 'children': ['103', '110', '119', '123']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'dp1'}; {'id': '110', 'type': 'delete_statement', 'children': ['111']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dps'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dps'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dp1'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'maxcount'}, {'id': '123', 'type': 'break_statement', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'raise_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '140']}; {'id': '134', 'type': 'attribute', 'children': ['135', '139']}, {'id': '135', 'type': 'parenthesized_expression', 'children': ['136']}; {'id': '136', 'type': 'concatenated_string', 'children': ['137', '138']}, {'id': '137', 'type': 'string', 'children': [], 'value': '"Unable to find ordering for derived "'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"parameter in component \'{0}\'"'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ordering'} | def order_derived_parameters(component):
if len(component.derived_parameters) == 0:
return []
ordering = []
dps = []
for dp in component.derived_parameters:
dps.append(dp.name)
maxcount = 5
count = maxcount
while count > 0 and dps != []:
count = count - 1
for dp1 in dps:
value = component.derived_parameters[dp1].value
found = False
for dp2 in dps:
if dp1 != dp2 and dp2 in value:
found = True
if not found:
ordering.append(dp1)
del dps[dps.index(dp1)]
count = maxcount
break
if count == 0:
raise SimBuildError(("Unable to find ordering for derived "
"parameter in component '{0}'").format(component))
return ordering |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_derived_variables'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '22', '55', '91', '95', '238', '258']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dvs'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dvsnoexp'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'maxcount'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'regime'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'derived_variables'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34', '44']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expression_tree'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dvsnoexp'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dv'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '44', 'type': 'else_clause', 'children': ['45']}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dvs'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '60']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dv'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'conditional_derived_variables'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'if_statement', 'children': ['62', '70', '80']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '69'], 'value': '=='}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cases'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'dvsnoexp'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'dv'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'dvs'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'maxcount'}, {'id': '95', 'type': 'while_statement', 'children': ['96', '103']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '100'], 'value': 'and'}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '>'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '!='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dvs'}; {'id': '102', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '103', 'type': 'block', 'children': ['104', '110']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '-'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'dv1'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dvs'}, {'id': '113', 'type': 'block', 'children': ['114', '139', '143', '213']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '120', '129']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'in'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dv1'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'derived_variables'}; {'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': 'dv'}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'derived_variables'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'dv1'}, {'id': '129', 'type': 'else_clause', 'children': ['130']}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '134', 'type': 'subscript', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'conditional_derived_variables'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dv1'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '142', 'type': 'False', 'children': []}, {'id': '143', 'type': 'if_statement', 'children': ['144', '149', '175']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'dv'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'DerivedVariable'}, {'id': '149', 'type': 'block', 'children': ['150', '156']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'exp_tree'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'dv'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'expression_tree'}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'dv2'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'dvs'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '170']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'and'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '!='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'dv1'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'dv2'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'is_var_in_exp_tree'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dv2'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'exp_tree'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '174', 'type': 'True', 'children': []}, {'id': '175', 'type': 'else_clause', 'children': ['176']}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'for_statement', 'children': ['178', '179', '182']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'case'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'dv'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'cases'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'for_statement', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'dv2'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'dvs'}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'if_statement', 'children': ['188', '208']}; {'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '!='}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'dv1'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dv2'}; {'id': '192', 'type': 'parenthesized_expression', 'children': ['193']}, {'id': '193', 'type': 'boolean_operator', 'children': ['194', '201'], 'value': 'or'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'is_var_in_exp_tree'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dv2'}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'condition_expression_tree'}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'is_var_in_exp_tree'}, {'id': '203', 'type': 'argument_list', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'dv2'}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'case'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'value_expression_tree'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '212', 'type': 'True', 'children': []}, {'id': '213', 'type': 'if_statement', 'children': ['214', '216']}; {'id': '214', 'type': 'not_operator', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '216', 'type': 'block', 'children': ['217', '224', '233', '237']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'dv1'}; {'id': '224', 'type': 'delete_statement', 'children': ['225']}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'dvs'}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'dvs'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'dv1'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'maxcount'}, {'id': '237', 'type': 'break_statement', 'children': []}; {'id': '238', 'type': 'if_statement', 'children': ['239', '242']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '=='}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'block', 'children': ['243']}, {'id': '243', 'type': 'raise_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '254']}; {'id': '248', 'type': 'attribute', 'children': ['249', '253']}, {'id': '249', 'type': 'parenthesized_expression', 'children': ['250']}; {'id': '250', 'type': 'concatenated_string', 'children': ['251', '252']}, {'id': '251', 'type': 'string', 'children': [], 'value': '"Unable to find ordering for derived "'}; {'id': '252', 'type': 'string', 'children': [], 'value': '"variables in regime \'{0}\'"'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'regime'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '258', 'type': 'return_statement', 'children': ['259']}, {'id': '259', 'type': 'binary_operator', 'children': ['260', '261'], 'value': '+'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'dvsnoexp'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'ordering'} | def order_derived_variables(regime):
ordering = []
dvs = []
dvsnoexp = []
maxcount = 5
for dv in regime.derived_variables:
if dv.expression_tree == None:
dvsnoexp.append(dv.name)
else:
dvs.append(dv.name)
for dv in regime.conditional_derived_variables:
if len(dv.cases) == 0:
dvsnoexp.append(dv.name)
else:
dvs.append(dv.name)
count = maxcount
while count > 0 and dvs != []:
count = count - 1
for dv1 in dvs:
if dv1 in regime.derived_variables:
dv = regime.derived_variables[dv1]
else:
dv = regime.conditional_derived_variables[dv1]
found = False
if isinstance(dv, DerivedVariable):
exp_tree = dv.expression_tree
for dv2 in dvs:
if dv1 != dv2 and is_var_in_exp_tree(dv2, exp_tree):
found = True
else:
for case in dv.cases:
for dv2 in dvs:
if dv1 != dv2 and (is_var_in_exp_tree(dv2, case.condition_expression_tree) or
is_var_in_exp_tree(dv2, case.value_expression_tree)):
found = True
if not found:
ordering.append(dv1)
del dvs[dvs.index(dv1)]
count = maxcount
break
if count == 0:
raise SimBuildError(("Unable to find ordering for derived "
"variables in regime '{0}'").format(regime.name))
return dvsnoexp + ordering |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_event_connections'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'structure'}; {'id': '8', 'type': 'block', 'children': ['9', '30']}, {'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': 'debug'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"\\n++++++++ Calling build_event_connections of %s with runnable %s, parent %s"'}; {'id': '20', 'type': 'tuple', 'children': ['21', '24', '27']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'runnable'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'structure'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'event_connections'}, {'id': '35', 'type': 'block', 'children': ['36', '50', '63', '76', '170', '176', '182', '222', '260', '284']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'toxml'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'source'}, {'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': 'runnable'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'target'}; {'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': 'runnable'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80', '146']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '80', 'type': 'block', 'children': ['81', '93', '101', '117', '132', '142']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'receiver_template'}; {'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': 'build_runnable'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'receiver_template'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'receiver'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"{0}__{1}__"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'receiver_template'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'receiver_container'}, {'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': 'target'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'add_attachment'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'receiver'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'receiver_container'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'add_child'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'receiver_template'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '146', 'type': 'else_clause', 'children': ['147']}, {'id': '147', 'type': 'block', 'children': ['148', '159']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'runnable'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'from_'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'target_port'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '185']}, {'id': '183', 'type': 'not_operator', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '195', '204']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '194'], 'value': '=='}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'event_out_ports'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '199', 'type': 'subscript', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'event_out_ports'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'else_clause', 'children': ['205']}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'raise_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '218']}, {'id': '211', 'type': 'attribute', 'children': ['212', '217']}; {'id': '212', 'type': 'parenthesized_expression', 'children': ['213']}, {'id': '213', 'type': 'concatenated_string', 'children': ['214', '215', '216']}; {'id': '214', 'type': 'string', 'children': [], 'value': '"No source event port "'}, {'id': '215', 'type': 'string', 'children': [], 'value': '"uniquely identifiable"'}; {'id': '216', 'type': 'string', 'children': [], 'value': '" in \'{0}\'"'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '225']}, {'id': '223', 'type': 'not_operator', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'if_statement', 'children': ['227', '235', '244']}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '234'], 'value': '=='}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'event_in_ports'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '239', 'type': 'subscript', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'event_in_ports'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'raise_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '258']}, {'id': '251', 'type': 'attribute', 'children': ['252', '257']}; {'id': '252', 'type': 'parenthesized_expression', 'children': ['253']}, {'id': '253', 'type': 'concatenated_string', 'children': ['254', '255', '256']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"No destination event port "'}, {'id': '255', 'type': 'string', 'children': [], 'value': '"uniquely identifiable "'}; {'id': '256', 'type': 'string', 'children': [], 'value': '"in \'{0}\'"'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '260', 'type': 'if_statement', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '264', 'type': 'block', 'children': ['265']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '%'}; {'id': '270', 'type': 'string', 'children': [], 'value': '"register_event_out_callback\\n Source: %s, %s (port: %s) \\n -> %s, %s (port: %s)"'}, {'id': '271', 'type': 'tuple', 'children': ['272', '273', '277', '278', '279', '283']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'target_port'}; {'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': 'source'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'register_event_out_callback'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291', '292']}; {'id': '290', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '292', 'type': 'lambda', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'inc_event_in'}, {'id': '297', 'type': 'argument_list', 'children': ['298']} | def build_event_connections(self, component, runnable, structure):
if self.debug: print("\n++++++++ Calling build_event_connections of %s with runnable %s, parent %s"%(component.id, runnable.id, runnable.parent))
for ec in structure.event_connections:
if self.debug: print(ec.toxml())
source = runnable.parent.resolve_path(ec.from_)
target = runnable.parent.resolve_path(ec.to)
if ec.receiver:
receiver_template = self.build_runnable(ec.receiver,
target)
receiver = receiver_template.copy()
receiver.id = "{0}__{1}__".format(component.id,
receiver_template.id)
if ec.receiver_container:
target.add_attachment(receiver, ec.receiver_container)
target.add_child(receiver_template.id, receiver)
target = receiver
else:
source = runnable.resolve_path(ec.from_)
target = runnable.resolve_path(ec.to)
source_port = ec.source_port
target_port = ec.target_port
if not source_port:
if len(source.event_out_ports) == 1:
source_port = source.event_out_ports[0]
else:
raise SimBuildError(("No source event port "
"uniquely identifiable"
" in '{0}'").format(source.id))
if not target_port:
if len(target.event_in_ports) == 1:
target_port = target.event_in_ports[0]
else:
raise SimBuildError(("No destination event port "
"uniquely identifiable "
"in '{0}'").format(target))
if self.debug: print("register_event_out_callback\n Source: %s, %s (port: %s) \n -> %s, %s (port: %s)"%(source, id(source), source_port, target, id(target), target_port))
source.register_event_out_callback(\
source_port, lambda: target.inc_event_in(target_port)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_foreach'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'foreach'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '34', '45']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '%'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"\\n++++++++ Calling build_foreach of %s with runnable %s, parent %s, name_mappings: %s"'}, {'id': '23', 'type': 'tuple', 'children': ['24', '27', '30', '33']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'runnable'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'target_array'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'runnable'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'foreach'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'instances'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'target_runnable'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'target_array'}; {'id': '48', 'type': 'block', 'children': ['49', '67', '75', '114']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Applying contents of for_each to %s, as %s"'}; {'id': '60', 'type': 'tuple', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'target_runnable'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'foreach'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'as_'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '74']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'foreach'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'as_'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'target_runnable'}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '80']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fe2'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'foreach'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'for_eachs'}; {'id': '80', 'type': 'block', 'children': ['81', '92']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'target_array2'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'runnable'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'resolve_path'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fe2'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'target_runnable2'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'target_array2'}, {'id': '95', 'type': 'block', 'children': ['96', '104']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '103']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fe2'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'as_'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'target_runnable2'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'build_foreach'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112', '113']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'runnable'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'fe2'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}; {'id': '114', 'type': 'for_statement', 'children': ['115', '116', '119']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ec'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'foreach'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'event_connections'}, {'id': '119', 'type': 'block', 'children': ['120', '128', '136', '142', '148', '188', '226', '250']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'from_'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'name_mappings'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ec'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'target_port'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '151']}, {'id': '149', 'type': 'not_operator', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '161', '170']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '160'], 'value': '=='}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'event_out_ports'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'source_port'}, {'id': '165', 'type': 'subscript', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'event_out_ports'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'else_clause', 'children': ['171']}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'raise_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '184']}, {'id': '177', 'type': 'attribute', 'children': ['178', '183']}; {'id': '178', 'type': 'parenthesized_expression', 'children': ['179']}, {'id': '179', 'type': 'concatenated_string', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'string', 'children': [], 'value': '"No source event port "'}, {'id': '181', 'type': 'string', 'children': [], 'value': '"uniquely identifiable"'}; {'id': '182', 'type': 'string', 'children': [], 'value': '" in \'{0}\'"'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '191']}, {'id': '189', 'type': 'not_operator', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'if_statement', 'children': ['193', '201', '210']}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '200'], 'value': '=='}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'event_in_ports'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'target_port'}, {'id': '205', 'type': 'subscript', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'event_in_ports'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'else_clause', 'children': ['211']}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'raise_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'SimBuildError'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '224']}, {'id': '217', 'type': 'attribute', 'children': ['218', '223']}; {'id': '218', 'type': 'parenthesized_expression', 'children': ['219']}, {'id': '219', 'type': 'concatenated_string', 'children': ['220', '221', '222']}; {'id': '220', 'type': 'string', 'children': [], 'value': '"No destination event port "'}, {'id': '221', 'type': 'string', 'children': [], 'value': '"uniquely identifiable "'}; {'id': '222', 'type': 'string', 'children': [], 'value': '"in \'{0}\'"'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '%'}; {'id': '236', 'type': 'string', 'children': [], 'value': '"register_event_out_callback\\n Source: %s, %s (port: %s) \\n -> %s, %s (port: %s)"'}, {'id': '237', 'type': 'tuple', 'children': ['238', '239', '243', '244', '245', '249']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'target_port'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'register_event_out_callback'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258']}; {'id': '256', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'source_port'}; {'id': '258', 'type': 'lambda', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'inc_event_in'}, {'id': '263', 'type': 'argument_list', 'children': ['264']} | def build_foreach(self, component, runnable, foreach, name_mappings = {}):
if self.debug: print("\n++++++++ Calling build_foreach of %s with runnable %s, parent %s, name_mappings: %s"%(component.id, runnable.id, runnable.parent, name_mappings))
target_array = runnable.resolve_path(foreach.instances)
for target_runnable in target_array:
if self.debug: print("Applying contents of for_each to %s, as %s"%(target_runnable.id, foreach.as_))
name_mappings[foreach.as_] = target_runnable
for fe2 in foreach.for_eachs:
target_array2 = runnable.resolve_path(fe2.instances)
for target_runnable2 in target_array2:
name_mappings[fe2.as_] = target_runnable2
self.build_foreach(component, runnable, fe2, name_mappings)
for ec in foreach.event_connections:
source = name_mappings[ec.from_]
target = name_mappings[ec.to]
source_port = ec.source_port
target_port = ec.target_port
if not source_port:
if len(source.event_out_ports) == 1:
source_port = source.event_out_ports[0]
else:
raise SimBuildError(("No source event port "
"uniquely identifiable"
" in '{0}'").format(source.id))
if not target_port:
if len(target.event_in_ports) == 1:
target_port = target.event_in_ports[0]
else:
raise SimBuildError(("No destination event port "
"uniquely identifiable "
"in '{0}'").format(target))
if self.debug: print("register_event_out_callback\n Source: %s, %s (port: %s) \n -> %s, %s (port: %s)"%(source, id(source), source_port, target, id(target), target_port))
source.register_event_out_callback(\
source_port, lambda: target.inc_event_in(target_port)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_static_member_vars'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'class_'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'only_init'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '17', '89', '98', '101', '110', '132', '175', '179', '216', '220', '224', '289', '298', '300']}; {'id': '12', 'type': 'import_statement', 'children': ['13']}, {'id': '13', 'type': 'aliased_import', 'children': ['14', '16']}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '25', '40']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'class_'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '25', 'type': 'block', 'children': ['26', '30']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'class_'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'must specify fpath'"}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42', '60', '66']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'class_'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '49', 'type': 'block', 'children': ['50', '54']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'class_instance'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'class_'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'class_'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'class_instance'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'class_'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71', '80']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_module_from_class'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'class_'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'get_modpath'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'readfrom'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '98', 'type': 'import_statement', 'children': ['99']}, {'id': '99', 'type': 'dotted_name', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'redbaron'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'baron'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'redbaron'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'RedBaron'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'baron'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '126']}, {'id': '115', 'type': 'boolean_operator', 'children': ['116', '121'], 'value': 'and'}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': '=='}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '126', 'type': 'block', 'children': ['127', '131']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'classnode'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '131', 'type': 'break_statement', 'children': []}; {'id': '132', 'type': 'function_definition', 'children': ['133', '134', '136']}, {'id': '133', 'type': 'function_name', 'children': [], 'value': 'find_parent_method'}; {'id': '134', 'type': 'parameters', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '136', 'type': 'block', 'children': ['137', '146']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'parent_find'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'def'"}; {'id': '146', 'type': 'if_statement', 'children': ['147', '156']}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '151'], 'value': 'and'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': 'is'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '155', 'type': 'None', 'children': []}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'if_statement', 'children': ['158', '165', '168']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '=='}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'return_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'find_parent_method'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'par'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'class_methods'}; {'id': '178', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '179', 'type': 'for_statement', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'classnode'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'if_statement', 'children': ['184', '189']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '=='}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'def'"}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'if_statement', 'children': ['191', '192', '207']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'only_init'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'if_statement', 'children': ['194', '199']}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '198'], 'value': '=='}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'__init__'"}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'class_methods'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '207', 'type': 'else_clause', 'children': ['208']}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'class_methods'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'class_vars'}, {'id': '219', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self_vars'}, {'id': '223', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '227']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'method_node'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'class_methods'}, {'id': '227', 'type': 'block', 'children': ['228', '240', '247']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self_var'}, {'id': '231', 'type': 'call', 'children': ['232', '239']}; {'id': '232', 'type': 'attribute', 'children': ['233', '238']}, {'id': '233', 'type': 'subscript', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'method_node'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'arguments'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '239', 'type': 'argument_list', 'children': []}; {'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': 'self_vars'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self_var'}, {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '255']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'assign'}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'method_node'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'find_all'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'string', 'children': [], 'value': "'assignment'"}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'if_statement', 'children': ['257', '271']}, {'id': '257', 'type': 'call', 'children': ['258', '267']}; {'id': '258', 'type': 'attribute', 'children': ['259', '266']}, {'id': '259', 'type': 'call', 'children': ['260', '265']}; {'id': '260', 'type': 'attribute', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'assign'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '265', 'type': 'argument_list', 'children': []}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '+'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self_var'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '271', 'type': 'block', 'children': ['272']}; {'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': 'class_vars'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '288']}, {'id': '279', 'type': 'attribute', 'children': ['280', '287']}; {'id': '280', 'type': 'subscript', 'children': ['281', '286']}, {'id': '281', 'type': 'attribute', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'assign'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '288', 'type': 'argument_list', 'children': []}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'static_attrs'}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'class_vars'}; {'id': '298', 'type': 'return_statement', 'children': ['299']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'static_attrs'}; {'id': '300', 'type': 'if_statement', 'children': ['301', '302']}, {'id': '301', 'type': 'False', 'children': []}; {'id': '302', 'type': 'block', 'children': ['303', '309', '313', '317', '338', '397', '401', '437', '446']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self_var'}; {'id': '306', 'type': 'subscript', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'self_vars'}; {'id': '308', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'complex_cases'}; {'id': '312', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'simple_cases'}; {'id': '316', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'all_self_ref'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'classnode'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'find_all'}; {'id': '324', 'type': 'argument_list', 'children': ['325', '326']}, {'id': '325', 'type': 'string', 'children': [], 'value': "'name_'"}; {'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'binary_operator', 'children': ['334', '337'], 'value': '+'}; {'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '+'}, {'id': '335', 'type': 'string', 'children': [], 'value': "'.*'"}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'self_var'}, {'id': '337', 'type': 'string', 'children': [], 'value': "'\\\\.*'"}; {'id': '338', 'type': 'for_statement', 'children': ['339', '340', '341']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'all_self_ref'}, {'id': '341', 'type': 'block', 'children': ['342', '352']}; {'id': '342', 'type': 'if_statement', 'children': ['343', '350']}, {'id': '343', 'type': 'comparison_operator', 'children': ['344', '349'], 'value': '=='}; {'id': '344', 'type': 'attribute', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '349', 'type': 'string', 'children': [], 'value': "'def_argument'"}; {'id': '350', 'type': 'block', 'children': ['351']}, {'id': '351', 'type': 'continue_statement', 'children': []}; {'id': '352', 'type': 'if_statement', 'children': ['353', '360']}, {'id': '353', 'type': 'comparison_operator', 'children': ['354', '359'], 'value': '=='}; {'id': '354', 'type': 'attribute', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '359', 'type': 'string', 'children': [], 'value': "'atomtrailers'"}; {'id': '360', 'type': 'block', 'children': ['361', '367']}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'atom'}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '367', 'type': 'if_statement', 'children': ['368', '380', '388']}; {'id': '368', 'type': 'comparison_operator', 'children': ['369', '379'], 'value': '<='}, {'id': '369', 'type': 'call', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'depth'}, {'id': '373', 'type': 'argument_list', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'fst'}; {'id': '378', 'type': 'argument_list', 'children': []}, {'id': '379', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '380', 'type': 'block', 'children': ['381']}, {'id': '381', 'type': 'expression_statement', 'children': ['382']}; {'id': '382', 'type': 'call', 'children': ['383', '386']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'simple_cases'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '386', 'type': 'argument_list', 'children': ['387']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'atom'}; {'id': '388', 'type': 'else_clause', 'children': ['389']}, {'id': '389', 'type': 'block', 'children': ['390']}; {'id': '390', 'type': 'expression_statement', 'children': ['391']}, {'id': '391', 'type': 'call', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'complex_cases'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '395', 'type': 'argument_list', 'children': ['396']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'atom'}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'assignment', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'accessed_attrs'}; {'id': '400', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '401', 'type': 'for_statement', 'children': ['402', '403', '404']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'simple_cases'}; {'id': '404', 'type': 'block', 'children': ['405']}, {'id': '405', 'type': 'if_statement', 'children': ['406', '417']}; {'id': '406', 'type': 'comparison_operator', 'children': ['407', '416'], 'value': '=='}, {'id': '407', 'type': 'call', 'children': ['408', '415']}; {'id': '408', 'type': 'attribute', 'children': ['409', '414']}, {'id': '409', 'type': 'subscript', 'children': ['410', '413']}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '413', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '415', 'type': 'argument_list', 'children': []}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'self_var'}, {'id': '417', 'type': 'block', 'children': ['418', '430']}; {'id': '418', 'type': 'expression_statement', 'children': ['419']}, {'id': '419', 'type': 'assignment', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '421', 'type': 'call', 'children': ['422', '429']}; {'id': '422', 'type': 'attribute', 'children': ['423', '428']}, {'id': '423', 'type': 'subscript', 'children': ['424', '427']}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '427', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '429', 'type': 'argument_list', 'children': []}; {'id': '430', 'type': 'expression_statement', 'children': ['431']}, {'id': '431', 'type': 'call', 'children': ['432', '435']}; {'id': '432', 'type': 'attribute', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'accessed_attrs'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '435', 'type': 'argument_list', 'children': ['436']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '437', 'type': 'expression_statement', 'children': ['438']}; {'id': '438', 'type': 'assignment', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'accessed_attrs'}; {'id': '440', 'type': 'call', 'children': ['441', '444']}, {'id': '441', 'type': 'attribute', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '444', 'type': 'argument_list', 'children': ['445']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'accessed_attrs'}; {'id': '446', 'type': 'expression_statement', 'children': ['447']}, {'id': '447', 'type': 'call', 'children': ['448', '451']}; {'id': '448', 'type': 'attribute', 'children': ['449', '450']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'setdiff'}, {'id': '451', 'type': 'argument_list', 'children': ['452', '453']}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'accessed_attrs'}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'class_vars'} | def check_static_member_vars(class_, fpath=None, only_init=True):
import utool as ut
if isinstance(class_, six.string_types):
classname = class_
if fpath is None:
raise Exception('must specify fpath')
else:
if not isinstance(class_, type):
class_instance = class_
class_ = class_instance.__class__
classname = class_.__name__
if fpath is None:
module = ut.get_module_from_class(class_)
fpath = ut.get_modpath(module)
sourcecode = ut.readfrom(fpath)
import redbaron
baron = redbaron.RedBaron(sourcecode)
for node in baron:
if node.type == 'class' and node.name == classname:
classnode = node
break
def find_parent_method(node):
par = node.parent_find('def')
if par is not None and par.parent is not None:
if par.parent.type == 'class':
return par
else:
return find_parent_method(par)
class_methods = []
for node in classnode:
if node.type == 'def':
if only_init:
if node.name == '__init__':
class_methods.append(node)
else:
class_methods.append(node)
class_vars = []
self_vars = []
for method_node in class_methods:
self_var = method_node.arguments[0].dumps()
self_vars.append(self_var)
for assign in method_node.find_all('assignment'):
if assign.target.dumps().startswith(self_var + '.'):
class_vars.append(assign.target.value[1].dumps())
static_attrs = ut.unique(class_vars)
return static_attrs
if False:
self_var = self_vars[0]
complex_cases = []
simple_cases = []
all_self_ref = classnode.find_all(
'name_', value=re.compile('.*' + self_var + '\\.*'))
for x in all_self_ref:
if x.parent.type == 'def_argument':
continue
if x.parent.type == 'atomtrailers':
atom = x.parent
if ut.depth(atom.fst()) <= 3:
simple_cases.append(atom)
else:
complex_cases.append(atom)
accessed_attrs = []
for x in simple_cases:
if x.value[0].dumps() == self_var:
attr = x.value[1].dumps()
accessed_attrs.append(attr)
accessed_attrs = ut.unique(accessed_attrs)
ut.setdiff(accessed_attrs, class_vars) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_funcnames_from_modpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'modpath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'include_methods'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '165']}, {'id': '9', 'type': 'import_statement', 'children': ['10']}; {'id': '10', 'type': 'aliased_import', 'children': ['11', '13']}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '16', '114']}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '20', '29', '38', '54']}, {'id': '17', 'type': 'import_statement', 'children': ['18']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'jedi'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'read_from'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'modpath'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'definition_list'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'jedi'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'funcname_list'}, {'id': '41', 'type': 'list_comprehension', 'children': ['42', '45', '48']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'definition'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'definition'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'definition_list'}; {'id': '48', 'type': 'if_clause', 'children': ['49']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '=='}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'definition'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'function'"}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'include_methods'}; {'id': '56', 'type': 'block', 'children': ['57', '71', '88']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'classdef_list'}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '62', '65']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'definition'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'definition'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'definition_list'}, {'id': '65', 'type': 'if_clause', 'children': ['66']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': '=='}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'definition'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'defined_methods'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'list_comprehension', 'children': ['80', '85']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'definition'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'defined_names'}; {'id': '84', 'type': 'argument_list', 'children': []}, {'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'definition'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'classdef_list'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'funcname_list'}, {'id': '91', 'type': 'list_comprehension', 'children': ['92', '95', '98']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'defined_methods'}; {'id': '98', 'type': 'if_clause', 'children': ['99']}, {'id': '99', 'type': 'boolean_operator', 'children': ['100', '105'], 'value': 'and'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '=='}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'function'"}, {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '112']}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '114', 'type': 'else_clause', 'children': ['115']}, {'id': '115', 'type': 'block', 'children': ['116', '119', '128', '137']}; {'id': '116', 'type': 'import_statement', 'children': ['117']}, {'id': '117', 'type': 'dotted_name', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'redbaron'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'read_from'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'modpath'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'baron'}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'redbaron'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'RedBaron'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'funcname_list'}; {'id': '140', 'type': 'list_comprehension', 'children': ['141', '144', '155']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'baron'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'find_all'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'def'"}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'include_methods'}, {'id': '155', 'type': 'if_clause', 'children': ['156']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '163']}; {'id': '158', 'type': 'attribute', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '165', 'type': 'return_statement', 'children': ['166']} | def get_funcnames_from_modpath(modpath, include_methods=True):
import utool as ut
if True:
import jedi
source = ut.read_from(modpath)
definition_list = jedi.names(source)
funcname_list = [definition.name for definition in definition_list if definition.type == 'function']
if include_methods:
classdef_list = [definition for definition in definition_list if definition.type == 'class']
defined_methods = ut.flatten([definition.defined_names() for definition in classdef_list])
funcname_list += [method.name for method in defined_methods
if method.type == 'function' and not method.name.startswith('_')]
else:
import redbaron
sourcecode = ut.read_from(modpath)
baron = redbaron.RedBaron(sourcecode)
funcname_list = [node.name for node in baron.find_all('def', recursive=include_methods)
if not node.name.startswith('_')]
return funcname_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_defined_by_module'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '14', '274']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'flag'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22', '142', '166']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'types'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ModuleType'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '30', '64']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'__file__'"}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'try_statement', 'children': ['32', '58']}; {'id': '32', 'type': 'block', 'children': ['33', '38', '49']}, {'id': '33', 'type': 'import_statement', 'children': ['34']}; {'id': '34', 'type': 'aliased_import', 'children': ['35', '37']}, {'id': '35', 'type': 'dotted_name', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_modname_from_modpath'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__file__'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '58', 'type': 'except_clause', 'children': ['59']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'flag'}, {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66', '82', '94']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'item_modpath'}, {'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': 'os'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'realpath'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '__file__'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'mod_fpath'}, {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '__file__'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'.pyc'"}, {'id': '93', 'type': 'string', 'children': [], 'value': "'.py'"}; {'id': '94', 'type': 'if_statement', 'children': ['95', '102', '107']}, {'id': '95', 'type': 'not_operator', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'mod_fpath'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'__init__.py'"}; {'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': 'flag'}; {'id': '106', 'type': 'False', 'children': []}, {'id': '107', 'type': 'else_clause', 'children': ['108']}; {'id': '108', 'type': 'block', 'children': ['109', '123', '133']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'modpath'}; {'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': 'realpath'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'mod_fpath'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'modpath'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'modpath'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'.pyc'"}; {'id': '132', 'type': 'string', 'children': [], 'value': "'.py'"}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'item_modpath'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'modpath'}; {'id': '142', 'type': 'elif_clause', 'children': ['143', '148']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'_utinfo'"}; {'id': '148', 'type': 'block', 'children': ['149', '157']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '152', 'type': 'subscript', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': '_utinfo'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'orig_func'"}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'is_defined_by_module'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'orig_func'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'id': '167', 'type': 'block', 'children': ['168', '181']}; {'id': '168', 'type': 'if_statement', 'children': ['169', '174']}, {'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': 'item'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'staticmethod'}; {'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': 'item'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': '__func__'}, {'id': '181', 'type': 'try_statement', 'children': ['182', '254']}; {'id': '182', 'type': 'block', 'children': ['183', '192', '198']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'func_globals'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'get_funcglobals'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'func_module_name'}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'func_globals'}, {'id': '197', 'type': 'string', 'children': [], 'value': "'__name__'"}; {'id': '198', 'type': 'if_statement', 'children': ['199', '202', '243']}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': '=='}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'func_module_name'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'line_profiler'"}; {'id': '202', 'type': 'block', 'children': ['203', '210', '222']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'valid_names'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '214']}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'is'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '213', 'type': 'None', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'augmented_assignment', 'children': ['217', '218'], 'value': '+='}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'valid_names'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '228']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': 'in'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'func_name'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'valid_names'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'if_statement', 'children': ['230', '238']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '237'], 'value': '>'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'func_name'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '238', 'type': 'block', 'children': ['239']}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '242', 'type': 'True', 'children': []}, {'id': '243', 'type': 'elif_clause', 'children': ['244', '249']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'func_module_name'}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'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': 'flag'}, {'id': '253', 'type': 'True', 'children': []}; {'id': '254', 'type': 'except_clause', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'if_statement', 'children': ['258', '263']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'__module__'"}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'flag'}, {'id': '267', 'type': 'comparison_operator', 'children': ['268', '271'], 'value': '=='}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '274', 'type': 'return_statement', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'flag'} | def is_defined_by_module(item, module, parent=None):
flag = False
if isinstance(item, types.ModuleType):
if not hasattr(item, '__file__'):
try:
import utool as ut
name = ut.get_modname_from_modpath(module.__file__)
flag = name in str(item)
except:
flag = False
else:
item_modpath = os.path.realpath(dirname(item.__file__))
mod_fpath = module.__file__.replace('.pyc', '.py')
if not mod_fpath.endswith('__init__.py'):
flag = False
else:
modpath = os.path.realpath(dirname(mod_fpath))
modpath = modpath.replace('.pyc', '.py')
flag = item_modpath.startswith(modpath)
elif hasattr(item, '_utinfo'):
orig_func = item._utinfo['orig_func']
flag = is_defined_by_module(orig_func, module, parent)
else:
if isinstance(item, staticmethod):
item = item.__func__
try:
func_globals = meta_util_six.get_funcglobals(item)
func_module_name = func_globals['__name__']
if func_module_name == 'line_profiler':
valid_names = dir(module)
if parent is not None:
valid_names += dir(parent)
if item.func_name in valid_names:
if len(item.func_name) > 6:
flag = True
elif func_module_name == module.__name__:
flag = True
except AttributeError:
if hasattr(item, '__module__'):
flag = item.__module__ == module.__name__
return flag |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_funcs_called_with_kwargs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'target_kwargs_name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'kwargs'"}; {'id': '8', 'type': 'block', 'children': ['9', '11', '14', '20', '29', '33', '39', '83', '399', '415']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'import_statement', 'children': ['12']}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '+'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'from __future__ import print_function\\n'"}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pt'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'child_funcnamess'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '38'], 'value': 'or'}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'VERYVERB_INSPECT'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '41', 'type': 'block', 'children': ['42', '47', '55', '60', '65', '68', '73']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'\\nInput:'"}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'target_kwargs_name = %r'"}, {'id': '53', 'type': 'tuple', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'target_kwargs_name'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'\\nSource:'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sourcecode'}, {'id': '65', 'type': 'import_statement', 'children': ['66']}; {'id': '66', 'type': 'dotted_name', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'astor'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'\\nParse:'"}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'astor'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'dump'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'pt'}, {'id': '83', 'type': 'class_definition', 'children': ['84', '85', '89']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'KwargParseVisitor'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'NodeVisitor'}, {'id': '89', 'type': 'block', 'children': ['90', '174']}; {'id': '90', 'type': 'function_definition', 'children': ['91', '92', '95']}, {'id': '91', 'type': 'function_name', 'children': [], 'value': 'visit_FunctionDef'}; {'id': '92', 'type': 'parameters', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '95', 'type': 'block', 'children': ['96', '119', '159']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '98', 'type': 'block', 'children': ['99', '107']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'\\nVISIT FunctionDef node = %r'"}, {'id': '105', 'type': 'tuple', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'node'}, {'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': 'binary_operator', 'children': ['112', '113'], 'value': '%'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'node.args.kwarg = %r'"}, {'id': '113', 'type': 'tuple', 'children': ['114']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'kwarg'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123', '132']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'PY2'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'kwarg_name'}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'if_statement', 'children': ['135', '142', '147']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '141'], 'value': 'is'}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwarg'}, {'id': '141', 'type': 'None', 'children': []}; {'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': 'kwarg_name'}; {'id': '146', 'type': 'None', 'children': []}, {'id': '147', 'type': 'else_clause', 'children': ['148']}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'kwarg_name'}; {'id': '152', 'type': 'attribute', 'children': ['153', '158']}, {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'kwarg'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '!='}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'kwarg_name'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'target_kwargs_name'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'NodeVisitor'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'generic_visit'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '174', 'type': 'function_definition', 'children': ['175', '176', '179']}, {'id': '175', 'type': 'function_name', 'children': [], 'value': 'visit_Call'}; {'id': '176', 'type': 'parameters', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '179', 'type': 'block', 'children': ['180', '191', '260', '389']}; {'id': '180', 'type': 'if_statement', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '%'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'\\nVISIT Call node = %r'"}, {'id': '189', 'type': 'tuple', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '191', 'type': 'if_statement', 'children': ['192', '201', '229', '248']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'Attribute'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'try_statement', 'children': ['203', '222']}, {'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': 'funcname'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '217'], 'value': '+'}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '216'], 'value': '+'}, {'id': '209', 'type': 'attribute', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '222', 'type': 'except_clause', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '228', 'type': 'None', 'children': []}, {'id': '229', 'type': 'elif_clause', 'children': ['230', '239']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'Name'}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'id': '243', 'type': 'attribute', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '248', 'type': 'else_clause', 'children': ['249']}, {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'raise_statement', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'binary_operator', 'children': ['255', '256'], 'value': '%'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'do not know how to parse: node.func = %r'"}; {'id': '256', 'type': 'tuple', 'children': ['257']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '260', 'type': 'if_statement', 'children': ['261', '264', '317']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'PY2'}; {'id': '264', 'type': 'block', 'children': ['265', '271', '282', '298']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}; {'id': '274', 'type': 'conditional_expression', 'children': ['275', '276', '279'], 'value': 'if'}, {'id': '275', 'type': 'None', 'children': []}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': 'is'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '278', 'type': 'None', 'children': []}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '282', 'type': 'if_statement', 'children': ['283', '290']}, {'id': '283', 'type': 'boolean_operator', 'children': ['284', '287'], 'value': 'and'}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': 'is'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '286', 'type': 'None', 'children': []}, {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '=='}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'target_kwargs_name'}; {'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': 'child_funcnamess'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '300', 'type': 'block', 'children': ['301', '309']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'binary_operator', 'children': ['306', '307'], 'value': '%'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'funcname = %r'"}, {'id': '307', 'type': 'tuple', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '315'], 'value': '%'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'kwargs_name = %r'"}, {'id': '315', 'type': 'tuple', 'children': ['316']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}, {'id': '317', 'type': 'else_clause', 'children': ['318']}; {'id': '318', 'type': 'block', 'children': ['319']}, {'id': '319', 'type': 'if_statement', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'keywords'}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'for_statement', 'children': ['325', '326', '329']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'keywords'}, {'id': '329', 'type': 'block', 'children': ['330']}; {'id': '330', 'type': 'if_statement', 'children': ['331', '336']}, {'id': '331', 'type': 'comparison_operator', 'children': ['332', '335'], 'value': 'is'}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '335', 'type': 'None', 'children': []}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'if_statement', 'children': ['338', '345']}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '340', 'type': 'argument_list', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '344', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '345', 'type': 'block', 'children': ['346', '354', '370']}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'assignment', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}, {'id': '349', 'type': 'attribute', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '354', 'type': 'if_statement', 'children': ['355', '362']}, {'id': '355', 'type': 'boolean_operator', 'children': ['356', '359'], 'value': 'and'}; {'id': '356', 'type': 'comparison_operator', 'children': ['357', '358'], 'value': 'is'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '358', 'type': 'None', 'children': []}, {'id': '359', 'type': 'comparison_operator', 'children': ['360', '361'], 'value': '=='}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'target_kwargs_name'}; {'id': '362', 'type': 'block', 'children': ['363']}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'child_funcnamess'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '370', 'type': 'if_statement', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '372', 'type': 'block', 'children': ['373', '381']}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}, {'id': '377', 'type': 'binary_operator', 'children': ['378', '379'], 'value': '%'}; {'id': '378', 'type': 'string', 'children': [], 'value': "'funcname = %r'"}, {'id': '379', 'type': 'tuple', 'children': ['380']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'id': '381', 'type': 'expression_statement', 'children': ['382']}; {'id': '382', 'type': 'call', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '384', 'type': 'argument_list', 'children': ['385']}, {'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '%'}; {'id': '386', 'type': 'string', 'children': [], 'value': "'kwargs_name = %r'"}, {'id': '387', 'type': 'tuple', 'children': ['388']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'kwargs_name'}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'call', 'children': ['391', '396']}, {'id': '391', 'type': 'attribute', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'NodeVisitor'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'generic_visit'}; {'id': '396', 'type': 'argument_list', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '399', 'type': 'try_statement', 'children': ['400', '410']}; {'id': '400', 'type': 'block', 'children': ['401']}, {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'call', 'children': ['403', '408']}, {'id': '403', 'type': 'attribute', 'children': ['404', '407']}; {'id': '404', 'type': 'call', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'KwargParseVisitor'}; {'id': '406', 'type': 'argument_list', 'children': []}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'visit'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'pt'}; {'id': '410', 'type': 'except_clause', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '412', 'type': 'block', 'children': ['413', '414']}, {'id': '413', 'type': 'raise_statement', 'children': []}; {'id': '414', 'type': 'pass_statement', 'children': []}, {'id': '415', 'type': 'return_statement', 'children': ['416']} | def find_funcs_called_with_kwargs(sourcecode, target_kwargs_name='kwargs'):
r
import ast
sourcecode = 'from __future__ import print_function\n' + sourcecode
pt = ast.parse(sourcecode)
child_funcnamess = []
debug = False or VERYVERB_INSPECT
if debug:
print('\nInput:')
print('target_kwargs_name = %r' % (target_kwargs_name,))
print('\nSource:')
print(sourcecode)
import astor
print('\nParse:')
print(astor.dump(pt))
class KwargParseVisitor(ast.NodeVisitor):
def visit_FunctionDef(self, node):
if debug:
print('\nVISIT FunctionDef node = %r' % (node,))
print('node.args.kwarg = %r' % (node.args.kwarg,))
if six.PY2:
kwarg_name = node.args.kwarg
else:
if node.args.kwarg is None:
kwarg_name = None
else:
kwarg_name = node.args.kwarg.arg
if kwarg_name != target_kwargs_name:
ast.NodeVisitor.generic_visit(self, node)
def visit_Call(self, node):
if debug:
print('\nVISIT Call node = %r' % (node,))
if isinstance(node.func, ast.Attribute):
try:
funcname = node.func.value.id + '.' + node.func.attr
except AttributeError:
funcname = None
elif isinstance(node.func, ast.Name):
funcname = node.func.id
else:
raise NotImplementedError(
'do not know how to parse: node.func = %r' % (node.func,))
if six.PY2:
kwargs = node.kwargs
kwargs_name = None if kwargs is None else kwargs.id
if funcname is not None and kwargs_name == target_kwargs_name:
child_funcnamess.append(funcname)
if debug:
print('funcname = %r' % (funcname,))
print('kwargs_name = %r' % (kwargs_name,))
else:
if node.keywords:
for kwargs in node.keywords:
if kwargs.arg is None:
if hasattr(kwargs.value, 'id'):
kwargs_name = kwargs.value.id
if funcname is not None and kwargs_name == target_kwargs_name:
child_funcnamess.append(funcname)
if debug:
print('funcname = %r' % (funcname,))
print('kwargs_name = %r' % (kwargs_name,))
ast.NodeVisitor.generic_visit(self, node)
try:
KwargParseVisitor().visit(pt)
except Exception:
raise
pass
return child_funcnamess |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_qt_set_leaf_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '6', 'type': 'block', 'children': ['7', '76', '90', '471']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_PREF'}, {'id': '9', 'type': 'block', 'children': ['10', '15', '20', '27', '38', '51', '65']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "''"}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'+--- [pref.qt_set_leaf_data]'"}; {'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']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] qvar = %r'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'qvar'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] _intern.name=%r'"}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] _intern.type_=%r'"}; {'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': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] type(_intern.value)=%r'"}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_intern'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] _intern.value=%r'"}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '84']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '83'], 'value': 'is'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_tree'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'raise_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'[Pref.qtleaf] Cannot set root preference'"}; {'id': '90', 'type': 'if_statement', 'children': ['91', '96']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'qt_is_editable'}, {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97', '101', '169', '177', '377', '425', '455']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'[Pref.qtleaf] BadThingsHappenedInPref'"}, {'id': '101', 'type': 'if_statement', 'children': ['102', '109', '115']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '108'], 'value': '=='}, {'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': '_intern'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'PrefNode'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'raise_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'[Pref.qtleaf] Qt can only change leafs'"}, {'id': '115', 'type': 'elif_clause', 'children': ['116', '123']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '122'], 'value': 'is'}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'block', 'children': ['124', '157']}; {'id': '124', 'type': 'function_definition', 'children': ['125', '126', '137']}, {'id': '125', 'type': 'function_name', 'children': [], 'value': 'cast_order'}; {'id': '126', 'type': 'parameters', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '128', 'type': 'default_parameter', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '130', 'type': 'list', 'children': ['131', '132', '133', '134'], 'value': '[bool, int, float, six.text_type]'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'try_statement', 'children': ['143', '153']}, {'id': '143', 'type': 'block', 'children': ['144', '151']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '153', 'type': 'except_clause', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'continue_statement', 'children': []}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cast_order'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'qvar'}, {'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': '_intern'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '176', 'type': 'argument_list', 'children': []}, {'id': '177', 'type': 'if_statement', 'children': ['178', '187', '214', '232', '252', '274', '307']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '186']}, {'id': '181', 'type': 'attribute', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '187', 'type': 'block', 'children': ['188', '196', '206']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'qvar = %r'"}; {'id': '194', 'type': 'tuple', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'util_type'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'smart_cast'}, {'id': '203', 'type': 'argument_list', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'qvar'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '%'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'new_val = %r'"}; {'id': '212', 'type': 'tuple', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '214', 'type': 'elif_clause', 'children': ['215', '224']}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '217', 'type': 'argument_list', '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': '_intern'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '232', 'type': 'elif_clause', 'children': ['233', '244']}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '241'], 'value': 'in'}; {'id': '234', 'type': 'call', 'children': ['235', '240']}, {'id': '235', 'type': 'attribute', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '240', 'type': 'argument_list', 'children': []}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'util_type'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'VALID_FLOAT_TYPES'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '252', 'type': 'elif_clause', 'children': ['253', '264']}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '255', 'type': 'argument_list', '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': '_intern'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '264', 'type': 'block', 'children': ['265']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '274', 'type': 'elif_clause', 'children': ['275', '284']}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '277', 'type': 'argument_list', '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': '_intern'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'PrefChoice'}; {'id': '284', 'type': 'block', 'children': ['285', '294']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '302']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '301'], 'value': '=='}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '300', 'type': 'argument_list', 'children': []}, {'id': '301', 'type': 'string', 'children': [], 'value': "'NONE'"}; {'id': '302', 'type': 'block', 'children': ['303']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '306', 'type': 'None', 'children': []}, {'id': '307', 'type': 'else_clause', 'children': ['308']}; {'id': '308', 'type': 'block', 'children': ['309']}, {'id': '309', 'type': 'try_statement', 'children': ['310', '349']}; {'id': '310', 'type': 'block', 'children': ['311', '321']}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '314', 'type': 'call', 'children': ['315', '320']}, {'id': '315', 'type': 'attribute', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '320', 'type': 'argument_list', 'children': []}, {'id': '321', 'type': 'if_statement', 'children': ['322', '325', '338']}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '324'], 'value': 'is'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '324', 'type': 'None', 'children': []}, {'id': '325', 'type': 'block', 'children': ['326']}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'assignment', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'qvar'}; {'id': '338', 'type': 'else_clause', 'children': ['339']}, {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'qvar'}, {'id': '349', 'type': 'except_clause', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'raise_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}, {'id': '355', 'type': 'argument_list', 'children': ['356', '370']}; {'id': '356', 'type': 'binary_operator', 'children': ['357', '362'], 'value': '%'}, {'id': '357', 'type': 'parenthesized_expression', 'children': ['358']}; {'id': '358', 'type': 'concatenated_string', 'children': ['359', '360', '361']}, {'id': '359', 'type': 'string', 'children': [], 'value': "'[Pref.qtleaf] Unknown internal type. '"}; {'id': '360', 'type': 'string', 'children': [], 'value': "'type(_intern.value) = %r, '"}, {'id': '361', 'type': 'string', 'children': [], 'value': "'_intern.get_type() = %r, '"}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '370', 'type': 'call', 'children': ['371', '376']}, {'id': '371', 'type': 'attribute', 'children': ['372', '375']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '376', 'type': 'argument_list', 'children': []}, {'id': '377', 'type': 'if_statement', 'children': ['378', '385']}; {'id': '378', 'type': 'call', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '380', 'type': 'argument_list', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'if_statement', 'children': ['387', '394', '399', '412']}, {'id': '387', 'type': 'comparison_operator', 'children': ['388', '393'], 'value': '=='}; {'id': '388', 'type': 'call', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '392', 'type': 'argument_list', 'children': []}, {'id': '393', 'type': 'string', 'children': [], 'value': "'none'"}; {'id': '394', 'type': 'block', 'children': ['395']}, {'id': '395', 'type': 'expression_statement', 'children': ['396']}; {'id': '396', 'type': 'assignment', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '398', 'type': 'None', 'children': []}, {'id': '399', 'type': 'elif_clause', 'children': ['400', '407']}; {'id': '400', 'type': 'comparison_operator', 'children': ['401', '406'], 'value': '=='}, {'id': '401', 'type': 'call', 'children': ['402', '405']}; {'id': '402', 'type': 'attribute', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '405', 'type': 'argument_list', 'children': []}; {'id': '406', 'type': 'string', 'children': [], 'value': "'true'"}, {'id': '407', 'type': 'block', 'children': ['408']}; {'id': '408', 'type': 'expression_statement', 'children': ['409']}, {'id': '409', 'type': 'assignment', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '411', 'type': 'True', 'children': []}; {'id': '412', 'type': 'elif_clause', 'children': ['413', '420']}, {'id': '413', 'type': 'comparison_operator', 'children': ['414', '419'], 'value': '=='}; {'id': '414', 'type': 'call', 'children': ['415', '418']}, {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '418', 'type': 'argument_list', 'children': []}, {'id': '419', 'type': 'string', 'children': [], 'value': "'false'"}; {'id': '420', 'type': 'block', 'children': ['421']}, {'id': '421', 'type': 'expression_statement', 'children': ['422']}; {'id': '422', 'type': 'assignment', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '424', 'type': 'False', 'children': []}, {'id': '425', 'type': 'if_statement', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_PREF'}, {'id': '427', 'type': 'block', 'children': ['428', '433', '440', '450']}; {'id': '428', 'type': 'expression_statement', 'children': ['429']}, {'id': '429', 'type': 'call', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '431', 'type': 'argument_list', 'children': ['432']}; {'id': '432', 'type': 'string', 'children': [], 'value': "'---'"}, {'id': '433', 'type': 'expression_statement', 'children': ['434']}; {'id': '434', 'type': 'call', 'children': ['435', '436']}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '436', 'type': 'argument_list', 'children': ['437']}, {'id': '437', 'type': 'binary_operator', 'children': ['438', '439'], 'value': '%'}; {'id': '438', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] new_val=%r'"}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '440', 'type': 'expression_statement', 'children': ['441']}, {'id': '441', 'type': 'call', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '443', 'type': 'argument_list', 'children': ['444']}; {'id': '444', 'type': 'binary_operator', 'children': ['445', '446'], 'value': '%'}, {'id': '445', 'type': 'string', 'children': [], 'value': "'[pref.qt_set_leaf_data] type(new_val)=%r'"}; {'id': '446', 'type': 'call', 'children': ['447', '448']}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '448', 'type': 'argument_list', 'children': ['449']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'new_val'}; {'id': '450', 'type': 'expression_statement', 'children': ['451']}, {'id': '451', 'type': 'call', 'children': ['452', '453']}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '453', 'type': 'argument_list', 'children': ['454']}; {'id': '454', 'type': 'string', 'children': [], 'value': "'L____ [pref.qt_set_leaf_data]'"}, {'id': '455', 'type': 'return_statement', 'children': ['456']}; {'id': '456', 'type': 'call', 'children': ['457', '464']}, {'id': '457', 'type': 'attribute', 'children': ['458', '463']}; {'id': '458', 'type': 'attribute', 'children': ['459', '462']}, {'id': '459', 'type': 'attribute', 'children': ['460', '461']}; {'id': '460', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '461', 'type': 'identifier', 'children': [], 'value': '_tree'}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '463', 'type': 'identifier', 'children': [], 'value': 'pref_update'}; {'id': '464', 'type': 'argument_list', 'children': ['465', '470']}, {'id': '465', 'type': 'attribute', 'children': ['466', '469']}; {'id': '466', 'type': 'attribute', 'children': ['467', '468']}, {'id': '467', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '468', 'type': 'identifier', 'children': [], 'value': '_intern'}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '470', 'type': 'identifier', 'children': [], 'value': 'new_val'}, {'id': '471', 'type': 'return_statement', 'children': ['472']} | def _qt_set_leaf_data(self, qvar):
if VERBOSE_PREF:
print('')
print('+--- [pref.qt_set_leaf_data]')
print('[pref.qt_set_leaf_data] qvar = %r' % qvar)
print('[pref.qt_set_leaf_data] _intern.name=%r' % self._intern.name)
print('[pref.qt_set_leaf_data] _intern.type_=%r' % self._intern.get_type())
print('[pref.qt_set_leaf_data] type(_intern.value)=%r' % type(self._intern.value))
print('[pref.qt_set_leaf_data] _intern.value=%r' % self._intern.value)
if self._tree.parent is None:
raise Exception('[Pref.qtleaf] Cannot set root preference')
if self.qt_is_editable():
new_val = '[Pref.qtleaf] BadThingsHappenedInPref'
if self._intern.value == PrefNode:
raise Exception('[Pref.qtleaf] Qt can only change leafs')
elif self._intern.value is None:
def cast_order(var, order=[bool, int, float, six.text_type]):
for type_ in order:
try:
ret = type_(var)
return ret
except Exception:
continue
new_val = cast_order(six.text_type(qvar))
self._intern.get_type()
if isinstance(self._intern.value, bool):
print('qvar = %r' % (qvar,))
new_val = util_type.smart_cast(qvar, bool)
print('new_val = %r' % (new_val,))
elif isinstance(self._intern.value, int):
new_val = int(qvar)
elif self._intern.get_type() in util_type.VALID_FLOAT_TYPES:
new_val = float(qvar)
elif isinstance(self._intern.value, six.string_types):
new_val = six.text_type(qvar)
elif isinstance(self._intern.value, PrefChoice):
new_val = six.text_type(qvar)
if new_val.upper() == 'NONE':
new_val = None
else:
try:
type_ = self._intern.get_type()
if type_ is not None:
new_val = type_(six.text_type(qvar))
else:
new_val = six.text_type(qvar)
except Exception:
raise NotImplementedError(
('[Pref.qtleaf] Unknown internal type. '
'type(_intern.value) = %r, '
'_intern.get_type() = %r, ')
% type(self._intern.value), self._intern.get_type())
if isinstance(new_val, six.string_types):
if new_val.lower() == 'none':
new_val = None
elif new_val.lower() == 'true':
new_val = True
elif new_val.lower() == 'false':
new_val = False
if VERBOSE_PREF:
print('---')
print('[pref.qt_set_leaf_data] new_val=%r' % new_val)
print('[pref.qt_set_leaf_data] type(new_val)=%r' % type(new_val))
print('L____ [pref.qt_set_leaf_data]')
return self._tree.parent.pref_update(self._intern.name, new_val)
return 'PrefNotEditable' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inject_all_external_modules'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'override+warn'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '28', '32', '68', '86']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'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': '__class__'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'NEW'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34', '49']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'NEW'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'classkey_list'}; {'id': '38', 'type': 'list_comprehension', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '__CLASSTYPE_ATTRIBUTES__'}, {'id': '43', 'type': 'if_clause', 'children': ['44']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51', '58']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'injected_modules'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_injected_modules'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'classkey_list'}, {'id': '61', 'type': 'list_comprehension', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'CLASS_INJECT_KEY'}, {'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'injected_modules'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'classkey'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'classkey_list'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'inject_instance'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '80', '83']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'classkey'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'classkey'}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'allow_override'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '85', 'type': 'False', 'children': []}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'classkey'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'classkey_list'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'postinject_instance'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'classkey'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'classkey'} | def inject_all_external_modules(self, classname=None,
allow_override='override+warn',
strict=True):
if classname is None:
classname = self.__class__.__name__
NEW = True
if NEW:
classkey_list = [key for key in __CLASSTYPE_ATTRIBUTES__
if key[0] == classname]
else:
injected_modules = get_injected_modules(classname)
classkey_list = [module.CLASS_INJECT_KEY
for module in injected_modules]
for classkey in classkey_list:
inject_instance(
self, classkey=classkey,
allow_override=allow_override, strict=False)
for classkey in classkey_list:
postinject_instance(
self, classkey=classkey) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inject_func_as_method'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'class_'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'allow_main'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '37', '49', '60', '69', '81', '236']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '40', 'type': 'None', 'children': []}, {'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': 'method_name'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_funcname'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '51', 'type': 'block', 'children': ['52', '56']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'allow_override'}, {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'allow_main'}, {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'old_method'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_method'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '__get__'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'old_method'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86', '93', '100', '140', '234']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_method_func'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'old_method'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'new_im_func'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_method_func'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_method'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '126']}, {'id': '101', 'type': 'boolean_operator', 'children': ['102', '108'], 'value': 'and'}; {'id': '102', 'type': 'boolean_operator', 'children': ['103', '105'], 'value': 'and'}, {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'allow_main'}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'is'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}, {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'parenthesized_expression', 'children': ['109']}, {'id': '109', 'type': 'boolean_operator', 'children': ['110', '118'], 'value': 'and'}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '117'], 'value': '!='}, {'id': '111', 'type': 'subscript', 'children': ['112', '116']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_funcglobals'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'__name__'"}, {'id': '117', 'type': 'string', 'children': [], 'value': "'__main__'"}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '125'], 'value': '=='}, {'id': '119', 'type': 'subscript', 'children': ['120', '124']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get_funcglobals'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'new_im_func'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'__name__'"}, {'id': '125', 'type': 'string', 'children': [], 'value': "'__main__'"}; {'id': '126', 'type': 'block', 'children': ['127', '139']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '131']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '130'], 'value': 'or'}, {'id': '129', 'type': 'True', 'children': []}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_CLASS'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '%'}, {'id': '137', 'type': 'string', 'children': [], 'value': "'[util_class] skipping re-inject of %r from __main__'"}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'method_name'}, {'id': '139', 'type': 'return_statement', 'children': []}; {'id': '140', 'type': 'if_statement', 'children': ['141', '148', '150', '163', '177']}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'old_method'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'new_method'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'new_im_func'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'return_statement', 'children': []}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '154']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'allow_override'}, {'id': '153', 'type': 'False', 'children': []}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'raise_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'Overrides are not allowed. Already have method_name=%r'"}, {'id': '161', 'type': 'parenthesized_expression', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'method_name'}, {'id': '163', 'type': 'elif_clause', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '=='}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'warn'"}, {'id': '167', 'type': 'block', 'children': ['168', '176']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'WARNING: Overrides are not allowed. Already have method_name=%r. Skipping'"}; {'id': '174', 'type': 'parenthesized_expression', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '176', 'type': 'return_statement', 'children': []}, {'id': '177', 'type': 'elif_clause', 'children': ['178', '181']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'allow_override'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'override+warn'"}, {'id': '181', 'type': 'block', 'children': ['182', '190', '202', '214', '224']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'WARNING: Overrides are allowed, but dangerous. method_name=%r.'"}; {'id': '188', 'type': 'parenthesized_expression', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '%'}, {'id': '195', 'type': 'string', 'children': [], 'value': "'old_method = %r, im_func=%s'"}; {'id': '196', 'type': 'tuple', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'old_method'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '%'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'new_method = %r, im_func=%s'"}; {'id': '208', 'type': 'tuple', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_method'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_im_func'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'subscript', 'children': ['219', '223']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'get_funcglobals'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'old_im_func'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'__name__'"}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'subscript', 'children': ['229', '233']}, {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'get_funcglobals'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'new_im_func'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'__name__'"}; {'id': '234', 'type': 'delete_statement', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'old_method'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'method_name'} | def inject_func_as_method(self, func, method_name=None, class_=None,
allow_override=False, allow_main=False,
verbose=True, override=None, force=False):
if override is not None:
allow_override = override
if method_name is None:
method_name = get_funcname(func)
if force:
allow_override = True
allow_main = True
old_method = getattr(self, method_name, None)
new_method = func.__get__(self, self.__class__)
if old_method is not None:
old_im_func = get_method_func(old_method)
new_im_func = get_method_func(new_method)
if not allow_main and old_im_func is not None and (
get_funcglobals(old_im_func)['__name__'] != '__main__' and
get_funcglobals(new_im_func)['__name__'] == '__main__'):
if True or VERBOSE_CLASS:
print('[util_class] skipping re-inject of %r from __main__' % method_name)
return
if old_method is new_method or old_im_func is new_im_func:
return
elif allow_override is False:
raise AssertionError(
'Overrides are not allowed. Already have method_name=%r' %
(method_name))
elif allow_override == 'warn':
print(
'WARNING: Overrides are not allowed. Already have method_name=%r. Skipping' %
(method_name))
return
elif allow_override == 'override+warn':
print('WARNING: Overrides are allowed, but dangerous. method_name=%r.' %
(method_name))
print('old_method = %r, im_func=%s' % (old_method, str(old_im_func)))
print('new_method = %r, im_func=%s' % (new_method, str(new_im_func)))
print(get_funcglobals(old_im_func)['__name__'])
print(get_funcglobals(new_im_func)['__name__'])
del old_method
setattr(self, method_name, new_method) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reload_class'}, {'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': 'verbose'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reload_module'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '17', '23', '31']}; {'id': '12', 'type': 'import_statement', 'children': ['13']}, {'id': '13', 'type': 'aliased_import', 'children': ['14', '16']}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '22'], 'value': 'or'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_CLASS'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '31', 'type': 'try_statement', 'children': ['32', '378']}; {'id': '32', 'type': 'block', 'children': ['33', '41', '55', '94', '141', '147', '155', '160', '172', '339']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'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']}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '54'], 'value': '+'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '+'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'[class] reloading '"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '53', 'type': 'string', 'children': [], 'value': "' from '"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '61', '80']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'_on_reload'"}, {'id': '61', 'type': 'block', 'children': ['62', '74']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'[class] calling _on_reload for '"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'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': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_on_reload'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'elif_clause', 'children': ['81', '84']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '>'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '93'], 'value': '+'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'[class] '"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '93', 'type': 'string', 'children': [], 'value': "' does not have an _on_reload function'"}; {'id': '94', 'type': 'function_definition', 'children': ['95', '96', '101']}, {'id': '95', 'type': 'function_name', 'children': [], 'value': 'find_base_clases'}; {'id': '96', 'type': 'parameters', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '98', 'type': 'default_parameter', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'find_base_clases'}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'block', 'children': ['102', '106', '127', '139']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'class_list'}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '111']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_baseclass'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '__bases__'}, {'id': '111', 'type': 'block', 'children': ['112', '120']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'parents'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'find_base_clases'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_baseclass'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'find_base_clases'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'class_list'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'parents'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'object'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'class_list'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '139', 'type': 'return_statement', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'class_list'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'head_class'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'class_list'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'find_base_clases'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'head_class'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'find_base_clases'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '158', 'type': 'set', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'HashComparable2'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'class_list'}, {'id': '163', 'type': 'list_comprehension', 'children': ['164', '165', '168']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '165', 'type': 'for_in_clause', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'class_list'}; {'id': '168', 'type': 'if_clause', 'children': ['169']}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'not'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '175']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'class_list'}, {'id': '175', 'type': 'block', 'children': ['176', '194', '242', '320', '330']}; {'id': '176', 'type': 'if_statement', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '191'], 'value': '+'}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '190'], 'value': '+'}, {'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'[class] reloading parent '"}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '190', 'type': 'string', 'children': [], 'value': "' from '"}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '194', 'type': 'if_statement', 'children': ['195', '200', '230']}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '199'], 'value': '=='}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '199', 'type': 'string', 'children': [], 'value': "'__main__'"}; {'id': '200', 'type': 'block', 'children': ['201', '211', '222']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'main_module_'}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'main_modname'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'get_modname_from_modpath'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'main_module_'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': '__file__'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'module_'}, {'id': '225', 'type': 'subscript', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'modules'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'main_modname'}; {'id': '230', 'type': 'else_clause', 'children': ['231']}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'module_'}, {'id': '235', 'type': 'subscript', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'modules'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '242', 'type': 'if_statement', 'children': ['243', '248', '261']}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '245', 'type': 'argument_list', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'module_'}, {'id': '247', 'type': 'string', 'children': [], 'value': "'rrr'"}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'if_statement', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'reload_module'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'module_'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'rrr'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '261', 'type': 'else_clause', 'children': ['262']}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'if_statement', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'reload_module'}, {'id': '265', 'type': 'block', 'children': ['266', '269', '283']}; {'id': '266', 'type': 'import_statement', 'children': ['267']}, {'id': '267', 'type': 'dotted_name', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'imp'}, {'id': '269', 'type': 'if_statement', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'binary_operator', 'children': ['277', '282'], 'value': '+'}, {'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '+'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'[class] reloading '"}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '282', 'type': 'string', 'children': [], 'value': "' with imp'"}, {'id': '283', 'type': 'try_statement', 'children': ['284', '292']}; {'id': '284', 'type': 'block', 'children': ['285']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'imp'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'reload'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'module_'}; {'id': '292', 'type': 'except_clause', 'children': ['293', '296']}, {'id': '293', 'type': 'tuple', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'ImportError'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '296', 'type': 'block', 'children': ['297', '308']}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '307'], 'value': '+'}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '+'}, {'id': '303', 'type': 'string', 'children': [], 'value': "'[class] fallback reloading '"}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': '_class'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '307', 'type': 'string', 'children': [], 'value': "' with imp'"}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'imp'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'load_source'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'module_'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'module_'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': '__file__'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': '_newclass'}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'module_'}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': '_class'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'reload_class_methods'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335', '336']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': '_newclass'}; {'id': '336', 'type': 'keyword_argument', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '339', 'type': 'if_statement', 'children': ['340', '345', '364']}; {'id': '340', 'type': 'call', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'string', 'children': [], 'value': "'_initialize_self'"}, {'id': '345', 'type': 'block', 'children': ['346', '358']}; {'id': '346', 'type': 'if_statement', 'children': ['347', '350']}, {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': '>'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '349', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '350', 'type': 'block', 'children': ['351']}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'binary_operator', 'children': ['356', '357'], 'value': '+'}; {'id': '356', 'type': 'string', 'children': [], 'value': "'[class] calling _initialize_self for '"}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': '_initialize_self'}, {'id': '363', 'type': 'argument_list', 'children': []}; {'id': '364', 'type': 'elif_clause', 'children': ['365', '368']}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '367'], 'value': '>'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '367', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '368', 'type': 'block', 'children': ['369']}, {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'call', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '372', 'type': 'argument_list', 'children': ['373']}, {'id': '373', 'type': 'binary_operator', 'children': ['374', '377'], 'value': '+'}; {'id': '374', 'type': 'binary_operator', 'children': ['375', '376'], 'value': '+'}, {'id': '375', 'type': 'string', 'children': [], 'value': "'[class] '"}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '377', 'type': 'string', 'children': [], 'value': "' does not have an _initialize_self function'"}; {'id': '378', 'type': 'except_clause', 'children': ['379', '383']}, {'id': '379', 'type': 'as_pattern', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '381', 'type': 'as_pattern_target', 'children': ['382']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '383', 'type': 'block', 'children': ['384', '400']}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}, {'id': '385', 'type': 'call', 'children': ['386', '389']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'printex'}, {'id': '389', 'type': 'argument_list', 'children': ['390', '391', '392']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '391', 'type': 'string', 'children': [], 'value': "'Error Reloading Class'"}; {'id': '392', 'type': 'keyword_argument', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '394', 'type': 'list', 'children': ['395', '396', '397', '398', '399'], 'value': "[\n 'modname', 'module', 'class_', 'class_list', 'self', ]"}, {'id': '395', 'type': 'string', 'children': [], 'value': "'modname'"}; {'id': '396', 'type': 'string', 'children': [], 'value': "'module'"}, {'id': '397', 'type': 'string', 'children': [], 'value': "'class_'"}; {'id': '398', 'type': 'string', 'children': [], 'value': "'class_list'"}, {'id': '399', 'type': 'string', 'children': [], 'value': "'self'"} | def reload_class(self, verbose=True, reload_module=True):
import utool as ut
verbose = verbose or VERBOSE_CLASS
classname = self.__class__.__name__
try:
modname = self.__class__.__module__
if verbose:
print('[class] reloading ' + classname + ' from ' + modname)
if hasattr(self, '_on_reload'):
if verbose > 1:
print('[class] calling _on_reload for ' + classname)
self._on_reload()
elif verbose > 1:
print('[class] ' + classname + ' does not have an _on_reload function')
def find_base_clases(_class, find_base_clases=None):
class_list = []
for _baseclass in _class.__bases__:
parents = find_base_clases(_baseclass, find_base_clases)
class_list.extend(parents)
if _class is not object:
class_list.append(_class)
return class_list
head_class = self.__class__
class_list = find_base_clases(head_class, find_base_clases)
ignore = {HashComparable2}
class_list = [_class for _class in class_list
if _class not in ignore]
for _class in class_list:
if verbose:
print('[class] reloading parent ' + _class.__name__ +
' from ' + _class.__module__)
if _class.__module__ == '__main__':
main_module_ = sys.modules[_class.__module__]
main_modname = ut.get_modname_from_modpath(main_module_.__file__)
module_ = sys.modules[main_modname]
else:
module_ = sys.modules[_class.__module__]
if hasattr(module_, 'rrr'):
if reload_module:
module_.rrr(verbose=verbose)
else:
if reload_module:
import imp
if verbose:
print('[class] reloading ' + _class.__module__ + ' with imp')
try:
imp.reload(module_)
except (ImportError, AttributeError):
print('[class] fallback reloading ' + _class.__module__ +
' with imp')
imp.load_source(module_.__name__, module_.__file__)
_newclass = getattr(module_, _class.__name__)
reload_class_methods(self, _newclass, verbose=verbose)
if hasattr(self, '_initialize_self'):
if verbose > 1:
print('[class] calling _initialize_self for ' + classname)
self._initialize_self()
elif verbose > 1:
print('[class] ' + classname + ' does not have an _initialize_self function')
except Exception as ex:
ut.printex(ex, 'Error Reloading Class', keys=[
'modname', 'module', 'class_', 'class_list', 'self', ])
raise |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'avl_join'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 't2'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '7', 'type': 'block', 'children': ['8', '19', '197']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '%'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'-- JOIN node=%r'"}, {'id': '17', 'type': 'tuple', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '27', '40', '62', '84']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'and'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 't1'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 't2'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '36']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'Join Case 1'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '40', 'type': 'elif_clause', 'children': ['41', '44']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 't1'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '53']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'Join Case 2'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'avl_insert_dir'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 't2'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'elif_clause', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 't2'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '75']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'Join Case 3'"}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'avl_insert_dir'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86', '93', '100']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'h1'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'height'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 't1'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'h2'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 't2'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '106', '134', '177']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '>'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'h1'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'h2'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '106', 'type': 'block', 'children': ['107', '115', '125']}, {'id': '107', 'type': 'if_statement', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'Join Case 4'"}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'avl_join_dir_recursive'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123', '124']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 't2'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ascii_tree'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 't1'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'top'"}; {'id': '134', 'type': 'elif_clause', 'children': ['135', '140']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '>'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'h2'}, {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'h1'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'block', 'children': ['141', '159', '169']}, {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '143', 'type': 'block', 'children': ['144', '149', '154']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'Join Case 5'"}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ascii_tree'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ascii_tree'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 't2'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'avl_join_dir_recursive'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167', '168']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 't2'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ascii_tree'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179', '187']}, {'id': '179', 'type': 'if_statement', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'DEBUG_JOIN'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'string', 'children': [], 'value': "'Join Case 6'"}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'avl_new_top'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195', '196']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 't2'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'return_statement', 'children': ['198']} | def avl_join(t1, t2, node):
if DEBUG_JOIN:
print('-- JOIN node=%r' % (node,))
if t1 is None and t2 is None:
if DEBUG_JOIN:
print('Join Case 1')
top = node
elif t1 is None:
if DEBUG_JOIN:
print('Join Case 2')
top = avl_insert_dir(t2, node, 0)
elif t2 is None:
if DEBUG_JOIN:
print('Join Case 3')
top = avl_insert_dir(t1, node, 1)
else:
h1 = height(t1)
h2 = height(t2)
if h1 > h2 + 1:
if DEBUG_JOIN:
print('Join Case 4')
top = avl_join_dir_recursive(t1, t2, node, 1)
if DEBUG_JOIN:
ascii_tree(t1, 'top')
elif h2 > h1 + 1:
if DEBUG_JOIN:
print('Join Case 5')
ascii_tree(t1)
ascii_tree(t2)
top = avl_join_dir_recursive(t1, t2, node, 0)
if DEBUG_JOIN:
ascii_tree(top)
else:
if DEBUG_JOIN:
print('Join Case 6')
top = avl_new_top(t1, t2, node, 0)
return top |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'git_sequence_editor_squash'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '13', '22', '27', '31', '35', '39', '92', '286', '295', '322', '327']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '8', 'type': 'import_statement', 'children': ['9']}, {'id': '9', 'type': 'aliased_import', 'children': ['10', '12']}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'read_from'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'new_lines'}; {'id': '38', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': 'get_commit_date'}, {'id': '41', 'type': 'parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'hashid'}, {'id': '43', 'type': 'block', 'children': ['44', '67', '72', '81', '90']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '50']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58', '61', '64']}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'git show -s --format=%ci '"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'hashid'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '60', 'type': 'False', 'children': []}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'quiet'}, {'id': '63', 'type': 'True', 'children': []}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pad_stdout'}; {'id': '66', 'type': 'False', 'children': []}, {'id': '67', 'type': 'import_from_statement', 'children': ['68', '70']}; {'id': '68', 'type': 'dotted_name', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'dateutil'}; {'id': '70', 'type': 'dotted_name', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stamp'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'stamp'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '92', 'type': 'for_statement', 'children': ['93', '94', '100']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '100', 'type': 'block', 'children': ['101', '110', '132', '138', '144', '157', '183', '187', '201', '251', '278', '282']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'commit_line'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '110', 'type': 'if_statement', 'children': ['111', '117']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '116'], 'value': '<'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'commit_line'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '117', 'type': 'block', 'children': ['118', '122', '126', '131']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}, {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}, {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'new_lines'}, {'id': '129', 'type': 'list', 'children': ['130'], 'value': '[line]'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '131', 'type': 'continue_statement', 'children': []}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'commit_line'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'hashid'}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'commit_line'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'commit_line'}; {'id': '154', 'type': 'slice', 'children': ['155', '156']}, {'id': '155', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '156', 'type': 'colon', 'children': []}, {'id': '157', 'type': 'try_statement', 'children': ['158', '166']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'get_commit_date'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'hashid'}; {'id': '166', 'type': 'except_clause', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '168', 'type': 'block', 'children': ['169', '173', '177', '182']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}; {'id': '172', 'type': 'None', 'children': []}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '176', 'type': 'None', 'children': []}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'augmented_assignment', 'children': ['179', '180'], 'value': '+='}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'new_lines'}; {'id': '180', 'type': 'list', 'children': ['181'], 'value': '[line]'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '182', 'type': 'continue_statement', 'children': []}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'orig_msg'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'can_squash'}; {'id': '190', 'type': 'boolean_operator', 'children': ['191', '198'], 'value': 'and'}, {'id': '191', 'type': 'boolean_operator', 'children': ['192', '195'], 'value': 'and'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'pick'"}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '=='}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '197', 'type': 'string', 'children': [], 'value': "'wip'"}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '=='}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'wip'"}, {'id': '201', 'type': 'if_statement', 'children': ['202', '209']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '206'], 'value': 'and'}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'is'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}, {'id': '205', 'type': 'None', 'children': []}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'wip'"}, {'id': '209', 'type': 'block', 'children': ['210', '216', '220', '231', '237']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'tdelta'}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '-'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'threshold_minutes'}, {'id': '219', 'type': 'integer', 'children': [], 'value': '45'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'td_min'}, {'id': '223', 'type': 'parenthesized_expression', 'children': ['224']}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '230'], 'value': '/'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'tdelta'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}, {'id': '229', 'type': 'argument_list', 'children': []}; {'id': '230', 'type': 'float', 'children': [], 'value': '60.'}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'augmented_assignment', 'children': ['233', '234'], 'value': '&='}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'can_squash'}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': '<'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'td_min'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'threshold_minutes'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '+'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '%'}, {'id': '243', 'type': 'string', 'children': [], 'value': "' -- tdelta=%r'"}; {'id': '244', 'type': 'tuple', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'get_timedelta_str'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'tdelta'}, {'id': '251', 'type': 'if_statement', 'children': ['252', '253', '271']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'can_squash'}, {'id': '253', 'type': 'block', 'children': ['254', '266']}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'new_line'}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'list', 'children': ['263', '264', '265'], 'value': "['squash', hashid, msg]"}, {'id': '263', 'type': 'string', 'children': [], 'value': "'squash'"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'hashid'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'augmented_assignment', 'children': ['268', '269'], 'value': '+='}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'new_lines'}, {'id': '269', 'type': 'list', 'children': ['270'], 'value': '[new_line]'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'new_line'}, {'id': '271', 'type': 'else_clause', 'children': ['272']}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'augmented_assignment', 'children': ['275', '276'], 'value': '+='}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'new_lines'}; {'id': '276', 'type': 'list', 'children': ['277'], 'value': '[line]'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'prev_msg'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'orig_msg'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'new_text'}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'new_lines'}, {'id': '295', 'type': 'function_definition', 'children': ['296', '297', '299']}; {'id': '296', 'type': 'function_name', 'children': [], 'value': 'get_commit_date'}, {'id': '297', 'type': 'parameters', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'hashid'}, {'id': '299', 'type': 'block', 'children': ['300', '314']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '307', 'type': 'argument_list', 'children': ['308', '311']}; {'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '+'}, {'id': '309', 'type': 'string', 'children': [], 'value': "'git show -s --format=%ci '"}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'hashid'}, {'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '313', 'type': 'False', 'children': []}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'binary_operator', 'children': ['319', '320'], 'value': '%'}, {'id': '319', 'type': 'string', 'children': [], 'value': "'out = %r'"}; {'id': '320', 'type': 'tuple', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'new_text'}, {'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': 'ut'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'write_to'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '334', '335']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'new_text'}, {'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '337', 'type': 'None', 'children': []} | def git_sequence_editor_squash(fpath):
r
import utool as ut
text = ut.read_from(fpath)
print(text)
prev_msg = None
prev_dt = None
new_lines = []
def get_commit_date(hashid):
out, err, ret = ut.cmd('git show -s --format=%ci ' + hashid, verbose=False, quiet=True, pad_stdout=False)
from dateutil import parser
stamp = out.strip('\n')
dt = parser.parse(stamp)
return dt
for line in text.split('\n'):
commit_line = line.split(' ')
if len(commit_line) < 3:
prev_msg = None
prev_dt = None
new_lines += [line]
continue
action = commit_line[0]
hashid = commit_line[1]
msg = ' ' .join(commit_line[2:])
try:
dt = get_commit_date(hashid)
except ValueError:
prev_msg = None
prev_dt = None
new_lines += [line]
continue
orig_msg = msg
can_squash = action == 'pick' and msg == 'wip' and prev_msg == 'wip'
if prev_dt is not None and prev_msg == 'wip':
tdelta = dt - prev_dt
threshold_minutes = 45
td_min = (tdelta.total_seconds() / 60.)
can_squash &= td_min < threshold_minutes
msg = msg + ' -- tdelta=%r' % (ut.get_timedelta_str(tdelta),)
if can_squash:
new_line = ' ' .join(['squash', hashid, msg])
new_lines += [new_line]
else:
new_lines += [line]
prev_msg = orig_msg
prev_dt = dt
new_text = '\n'.join(new_lines)
def get_commit_date(hashid):
out = ut.cmd('git show -s --format=%ci ' + hashid, verbose=False)
print('out = %r' % (out,))
print(new_text)
ut.write_to(fpath, new_text, n=None) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_proteintable'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pqdb'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'headerfields'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mergecutoff'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'isobaric'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'precursor'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'probability'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fdr'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pep'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'genecentric'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '54', '63', '75', '87', '99', '111', '123', '137', '152', '160', '169', '176', '187', '203', '230', '308']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pdmap'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'create_featuredata_map'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36', '41', '46', '51']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pqdb'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'genecentric'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'genecentric'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'psm_fill_fun'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pinfo'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'add_psms_to_proteindata'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pgene_fill_fun'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pinfo'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'add_protgene_to_protdata'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'count_fun'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pinfo'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'count_peps_psms'}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_uniques'}, {'id': '53', 'type': 'True', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'empty_return'}, {'id': '57', 'type': 'lambda', 'children': ['58', '62']}; {'id': '58', 'type': 'lambda_parameters', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '62', 'type': 'dictionary', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'iso_fun'}; {'id': '66', 'type': 'subscript', 'children': ['67', '74']}, {'id': '67', 'type': 'dictionary', 'children': ['68', '71']}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_isobaric_quant'}, {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'False', 'children': []}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'empty_return'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isobaric'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ms1_fun'}; {'id': '78', 'type': 'subscript', 'children': ['79', '86']}, {'id': '79', 'type': 'dictionary', 'children': ['80', '83']}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}, {'id': '81', 'type': 'True', 'children': []}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_precursor_quant'}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'False', 'children': []}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'empty_return'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'precursor'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'prob_fun'}; {'id': '90', 'type': 'subscript', 'children': ['91', '98']}, {'id': '91', 'type': 'dictionary', 'children': ['92', '95']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}, {'id': '93', 'type': 'True', 'children': []}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get_prot_probability'}, {'id': '95', 'type': 'pair', 'children': ['96', '97']}; {'id': '96', 'type': 'False', 'children': []}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'empty_return'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'probability'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fdr_fun'}; {'id': '102', 'type': 'subscript', 'children': ['103', '110']}, {'id': '103', 'type': 'dictionary', 'children': ['104', '107']}; {'id': '104', 'type': 'pair', 'children': ['105', '106']}, {'id': '105', 'type': 'True', 'children': []}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_prot_fdr'}, {'id': '107', 'type': 'pair', 'children': ['108', '109']}; {'id': '108', 'type': 'False', 'children': []}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'empty_return'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fdr'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pep_fun'}; {'id': '114', 'type': 'subscript', 'children': ['115', '122']}, {'id': '115', 'type': 'dictionary', 'children': ['116', '119']}; {'id': '116', 'type': 'pair', 'children': ['117', '118']}, {'id': '117', 'type': 'True', 'children': []}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'get_prot_pep'}, {'id': '119', 'type': 'pair', 'children': ['120', '121']}; {'id': '120', 'type': 'False', 'children': []}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'empty_return'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pep'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pdata_fun'}; {'id': '126', 'type': 'subscript', 'children': ['127', '134']}, {'id': '127', 'type': 'dictionary', 'children': ['128', '131']}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}, {'id': '129', 'type': 'True', 'children': []}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_protein_data_genecentric'}, {'id': '131', 'type': 'pair', 'children': ['132', '133']}; {'id': '132', 'type': 'False', 'children': []}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'get_protein_data'}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'genecentric'}; {'id': '136', 'type': 'False', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '142']}, {'id': '139', 'type': 'pattern_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'protein_sql'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pqdb'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'prepare_mergetable_sql'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '149', '150', '151']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'precursor'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'isobaric'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'probability'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'fdr'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'pep'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'accession_field'}, {'id': '155', 'type': 'subscript', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'prottabledata'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ACCESSIONS'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'genecentric'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'pqdb'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get_merged_features'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'protein_sql'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'proteins'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '179', 'type': 'dictionary', 'children': ['180']}; {'id': '180', 'type': 'pair', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'accession_field'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'p_acc'"}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'check_prot'}; {'id': '190', 'type': 'dictionary_comprehension', 'children': ['191', '194']}, {'id': '191', 'type': 'pair', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '194', 'type': 'for_in_clause', 'children': ['195', '198']}, {'id': '195', 'type': 'pattern_list', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '202', 'type': 'argument_list', 'children': []}, {'id': '203', 'type': 'if_statement', 'children': ['204', '213']}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '207'], 'value': 'or'}, {'id': '205', 'type': 'not_operator', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'mergecutoff'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'protein_pool_fdr_cutoff'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'protein'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'mergecutoff'}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'fill_mergefeature'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '219', '220', '221', '222', '223', '224', '225', '226', '227', '228', '229']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'iso_fun'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ms1_fun'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'prob_fun'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'fdr_fun'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'pep_fun'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'pdata_fun'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'headerfields'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'pdmap'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'accession_field'}; {'id': '230', 'type': 'for_statement', 'children': ['231', '232', '233']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '233', 'type': 'block', 'children': ['234', '246', '254', '292']}; {'id': '234', 'type': 'if_statement', 'children': ['235', '244']}, {'id': '235', 'type': 'boolean_operator', 'children': ['236', '237'], 'value': 'and'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'mergecutoff'}, {'id': '237', 'type': 'not_operator', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'protein_pool_fdr_cutoff'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'mergecutoff'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'continue_statement', 'children': []}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'p_acc'}, {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'protein'}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'p_acc'"}; {'id': '254', 'type': 'if_statement', 'children': ['255', '260']}, {'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': '!='}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'p_acc'}, {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'accession_field'}; {'id': '260', 'type': 'block', 'children': ['261', '269', '276']}, {'id': '261', 'type': 'if_statement', 'children': ['262', '265']}; {'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '!='}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'outprotein'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'check_prot'}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'yield', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'outprotein'}; {'id': '272', 'type': 'dictionary', 'children': ['273']}, {'id': '273', 'type': 'pair', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'accession_field'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'p_acc'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'check_prot'}, {'id': '279', 'type': 'dictionary_comprehension', 'children': ['280', '283']}; {'id': '280', 'type': 'pair', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '283', 'type': 'for_in_clause', 'children': ['284', '287']}; {'id': '284', 'type': 'pattern_list', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'outprotein'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '291', 'type': 'argument_list', 'children': []}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'fill_mergefeature'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '297', '298', '299', '300', '301', '302', '303', '304', '305', '306', '307']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'iso_fun'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ms1_fun'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'prob_fun'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'fdr_fun'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'pep_fun'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'pdata_fun'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'sqlfieldmap'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'headerfields'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'pdmap'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'accession_field'}; {'id': '308', 'type': 'if_statement', 'children': ['309', '312']}, {'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': '!='}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'outprotein'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'check_prot'}; {'id': '312', 'type': 'block', 'children': ['313']}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'yield', 'children': ['315']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'outprotein'} | def build_proteintable(pqdb, headerfields, mergecutoff, isobaric=False,
precursor=False, probability=False, fdr=False,
pep=False, genecentric=False):
pdmap = create_featuredata_map(pqdb, genecentric=genecentric,
psm_fill_fun=pinfo.add_psms_to_proteindata,
pgene_fill_fun=pinfo.add_protgene_to_protdata,
count_fun=pinfo.count_peps_psms,
get_uniques=True)
empty_return = lambda x, y, z: {}
iso_fun = {True: get_isobaric_quant, False: empty_return}[isobaric]
ms1_fun = {True: get_precursor_quant, False: empty_return}[precursor]
prob_fun = {True: get_prot_probability,
False: empty_return}[probability]
fdr_fun = {True: get_prot_fdr,
False: empty_return}[fdr]
pep_fun = {True: get_prot_pep,
False: empty_return}[pep]
pdata_fun = {True: get_protein_data_genecentric,
False: get_protein_data}[genecentric is not False]
protein_sql, sqlfieldmap = pqdb.prepare_mergetable_sql(precursor, isobaric,
probability, fdr,
pep)
accession_field = prottabledata.ACCESSIONS[genecentric]
proteins = pqdb.get_merged_features(protein_sql)
protein = next(proteins)
outprotein = {accession_field: protein[sqlfieldmap['p_acc']]}
check_prot = {k: v for k, v in outprotein.items()}
if not mergecutoff or protein_pool_fdr_cutoff(protein, sqlfieldmap,
mergecutoff):
fill_mergefeature(outprotein, iso_fun, ms1_fun, prob_fun, fdr_fun,
pep_fun, pdata_fun, protein, sqlfieldmap,
headerfields, pdmap, accession_field)
for protein in proteins:
if mergecutoff and not protein_pool_fdr_cutoff(protein, sqlfieldmap,
mergecutoff):
continue
p_acc = protein[sqlfieldmap['p_acc']]
if p_acc != outprotein[accession_field]:
if outprotein != check_prot:
yield outprotein
outprotein = {accession_field: p_acc}
check_prot = {k: v for k, v in outprotein.items()}
fill_mergefeature(outprotein, iso_fun, ms1_fun, prob_fun, fdr_fun,
pep_fun, pdata_fun, protein, sqlfieldmap,
headerfields, pdmap, accession_field)
if outprotein != check_prot:
yield outprotein |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'start_logging'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'appname'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'default'"}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'log_dir'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '19', '21', '23', '25', '27', '29', '37']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '19', 'type': 'global_statement', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '21', 'type': 'global_statement', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '__UTOOL_PRINT__'}, {'id': '23', 'type': 'global_statement', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '__UTOOL_WRITE__'}, {'id': '25', 'type': 'global_statement', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__UTOOL_FLUSH__'}, {'id': '27', 'type': 'global_statement', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '__CURRENT_LOG_FPATH__'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'LOGGING_VERBOSE'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'[utool] start_logging()'"}, {'id': '37', 'type': 'if_statement', 'children': ['38', '48', '394']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '44'], 'value': 'and'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '43'], 'value': 'and'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '__IN_MAIN_PROCESS__'}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__inside_doctest'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49', '57', '77', '81', '100', '109', '116', '128', '135', '141', '149', '157', '163', '172', '184', '212', '343', '367', '371', '375', '379']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'LOGGING_VERBOSE'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'[utool] start_logging()... rootcheck OK'"}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_log_fpath'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74']}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'next'"}, {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'appname'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'appname'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'log_dir'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '__CURRENT_LOG_FPATH__'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '85']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '84'], 'value': 'or'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'LOGGING_VERBOSE'}, {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'startmsg'}, {'id': '89', 'type': 'parenthesized_expression', 'children': ['90']}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '%'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'logging to log_fpath=%r'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_utool_print'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'startmsg'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'root'"}, {'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': '__UTOOL_ROOT_LOGGER__'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'string', 'children': [], 'value': "'DEBUG'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'logfile_handler'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'FileHandler'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'log_fpath'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'stdout_handler'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'CustomStreamHandler'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '__UTOOL_STDOUT__'}, {'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': 'stdout_handler'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'terminator'}; {'id': '140', 'type': 'string', 'children': [], 'value': "''"}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'add_logging_handler'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'logfile_handler'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'format_'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'file'"}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'add_logging_handler'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'stdout_handler'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'format_'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'stdout'"}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'propagate'}; {'id': '162', 'type': 'False', 'children': []}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '172', 'type': 'function_definition', 'children': ['173', '174', '177']}, {'id': '173', 'type': 'function_name', 'children': [], 'value': 'utool_flush'}; {'id': '174', 'type': 'parameters', 'children': ['175']}, {'id': '175', 'type': 'list_splat_pattern', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'stdout_handler'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '183', 'type': 'argument_list', 'children': []}; {'id': '184', 'type': 'function_definition', 'children': ['185', '186', '189']}, {'id': '185', 'type': 'function_name', 'children': [], 'value': 'utool_write'}; {'id': '186', 'type': 'parameters', 'children': ['187']}, {'id': '187', 'type': 'list_splat_pattern', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '189', 'type': 'block', 'children': ['190', '205']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'args'}, {'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': '__UTOOL_ROOT_LOGGER__'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '212', 'type': 'if_statement', 'children': ['213', '215', '279']}, {'id': '213', 'type': 'not_operator', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'PRINT_ALL_CALLERS'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'function_definition', 'children': ['217', '218', '221']}, {'id': '217', 'type': 'function_name', 'children': [], 'value': 'utool_print'}; {'id': '218', 'type': 'parameters', 'children': ['219']}, {'id': '219', 'type': 'list_splat_pattern', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '221', 'type': 'block', 'children': ['222', '226']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'endline'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '226', 'type': 'try_statement', 'children': ['227', '252']}, {'id': '227', 'type': 'block', 'children': ['228', '243']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'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': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'args'}, {'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': '__UTOOL_ROOT_LOGGER__'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '+'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'endline'}; {'id': '252', 'type': 'except_clause', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '254', 'type': 'block', 'children': ['255', '270']}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'new_msg'}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'meta_util_six'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ensure_unicode'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '270', 'type': 'return_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '+'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'new_msg'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'endline'}, {'id': '279', 'type': 'else_clause', 'children': ['280']}; {'id': '280', 'type': 'block', 'children': ['281']}, {'id': '281', 'type': 'function_definition', 'children': ['282', '283', '286']}; {'id': '282', 'type': 'function_name', 'children': [], 'value': 'utool_print'}, {'id': '283', 'type': 'parameters', 'children': ['284']}; {'id': '284', 'type': 'list_splat_pattern', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '286', 'type': 'block', 'children': ['287', '292', '296', '300', '307', '323']}, {'id': '287', 'type': 'import_statement', 'children': ['288']}; {'id': '288', 'type': 'aliased_import', 'children': ['289', '291']}, {'id': '289', 'type': 'dotted_name', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'utool_flush'}, {'id': '295', 'type': 'argument_list', 'children': []}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'endline'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'\\n\\n----------'"}, {'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': '__UTOOL_ROOT_LOGGER__'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'get_caller_name'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322']}, {'id': '321', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '322', 'type': 'integer', 'children': [], 'value': '20'}, {'id': '323', 'type': 'return_statement', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'binary_operator', 'children': ['330', '342'], 'value': '+'}; {'id': '330', 'type': 'call', 'children': ['331', '334']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '337', 'type': 'argument_list', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'endline'}, {'id': '343', 'type': 'function_definition', 'children': ['344', '345', '348']}; {'id': '344', 'type': 'function_name', 'children': [], 'value': 'utool_printdbg'}, {'id': '345', 'type': 'parameters', 'children': ['346']}; {'id': '346', 'type': 'list_splat_pattern', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'return_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': '__UTOOL_ROOT_LOGGER__'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'call', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '362', 'type': 'argument_list', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'assignment', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': '__UTOOL_WRITE__'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'utool_write'}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': '__UTOOL_FLUSH__'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'utool_flush'}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': '__UTOOL_PRINT__'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'utool_print'}, {'id': '379', 'type': 'if_statement', 'children': ['380', '383']}; {'id': '380', 'type': 'boolean_operator', 'children': ['381', '382'], 'value': 'or'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'LOGGING_VERBOSE'}, {'id': '383', 'type': 'block', 'children': ['384', '389']}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}, {'id': '385', 'type': 'call', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': '__UTOOL_PRINT__'}, {'id': '387', 'type': 'argument_list', 'children': ['388']}; {'id': '388', 'type': 'string', 'children': [], 'value': "'<__LOG_START__>'"}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'call', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': '__UTOOL_PRINT__'}; {'id': '392', 'type': 'argument_list', 'children': ['393']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'startmsg'}; {'id': '394', 'type': 'else_clause', 'children': ['395']}, {'id': '395', 'type': 'block', 'children': ['396']}; {'id': '396', 'type': 'if_statement', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'LOGGING_VERBOSE'}; {'id': '398', 'type': 'block', 'children': ['399', '404', '409', '419', '427']}, {'id': '399', 'type': 'expression_statement', 'children': ['400']}; {'id': '400', 'type': 'call', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '402', 'type': 'argument_list', 'children': ['403']}, {'id': '403', 'type': 'string', 'children': [], 'value': "'[utool] start_logging()... FAILED TO START'"}; {'id': '404', 'type': 'expression_statement', 'children': ['405']}, {'id': '405', 'type': 'call', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '407', 'type': 'argument_list', 'children': ['408']}; {'id': '408', 'type': 'string', 'children': [], 'value': "'DEBUG INFO'"}, {'id': '409', 'type': 'expression_statement', 'children': ['410']}; {'id': '410', 'type': 'call', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '412', 'type': 'argument_list', 'children': ['413']}, {'id': '413', 'type': 'binary_operator', 'children': ['414', '415'], 'value': '%'}; {'id': '414', 'type': 'string', 'children': [], 'value': "'__inside_doctest() = %r'"}, {'id': '415', 'type': 'tuple', 'children': ['416']}; {'id': '416', 'type': 'call', 'children': ['417', '418']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': '__inside_doctest'}; {'id': '418', 'type': 'argument_list', 'children': []}, {'id': '419', 'type': 'expression_statement', 'children': ['420']}; {'id': '420', 'type': 'call', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '422', 'type': 'argument_list', 'children': ['423']}, {'id': '423', 'type': 'binary_operator', 'children': ['424', '425'], 'value': '%'}; {'id': '424', 'type': 'string', 'children': [], 'value': "'__IN_MAIN_PROCESS__ = %r'"}, {'id': '425', 'type': 'tuple', 'children': ['426']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': '__IN_MAIN_PROCESS__'}, {'id': '427', 'type': 'expression_statement', 'children': ['428']}; {'id': '428', 'type': 'call', 'children': ['429', '430']}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '430', 'type': 'argument_list', 'children': ['431']}, {'id': '431', 'type': 'binary_operator', 'children': ['432', '433'], 'value': '%'}; {'id': '432', 'type': 'string', 'children': [], 'value': "'__UTOOL_ROOT_LOGGER__ = %r'"}, {'id': '433', 'type': 'tuple', 'children': ['434']} | def start_logging(log_fpath=None, mode='a', appname='default', log_dir=None):
r
global __UTOOL_ROOT_LOGGER__
global __UTOOL_PRINT__
global __UTOOL_WRITE__
global __UTOOL_FLUSH__
global __CURRENT_LOG_FPATH__
if LOGGING_VERBOSE:
print('[utool] start_logging()')
if __UTOOL_ROOT_LOGGER__ is None and __IN_MAIN_PROCESS__ and not __inside_doctest():
if LOGGING_VERBOSE:
print('[utool] start_logging()... rootcheck OK')
if log_fpath is None:
log_fpath = get_log_fpath(num='next', appname=appname, log_dir=log_dir)
__CURRENT_LOG_FPATH__ = log_fpath
if VERBOSE or LOGGING_VERBOSE:
startmsg = ('logging to log_fpath=%r' % log_fpath)
_utool_print()(startmsg)
__UTOOL_ROOT_LOGGER__ = logging.getLogger('root')
__UTOOL_ROOT_LOGGER__.setLevel('DEBUG')
logfile_handler = logging.FileHandler(log_fpath, mode=mode)
stdout_handler = CustomStreamHandler(__UTOOL_STDOUT__)
stdout_handler.terminator = ''
add_logging_handler(logfile_handler, format_='file')
add_logging_handler(stdout_handler, format_='stdout')
__UTOOL_ROOT_LOGGER__.propagate = False
__UTOOL_ROOT_LOGGER__.setLevel(logging.DEBUG)
def utool_flush(*args):
stdout_handler.flush()
def utool_write(*args):
msg = ', '.join(map(six.text_type, args))
__UTOOL_ROOT_LOGGER__.info(msg)
if not PRINT_ALL_CALLERS:
def utool_print(*args):
endline = '\n'
try:
msg = ', '.join(map(six.text_type, args))
return __UTOOL_ROOT_LOGGER__.info(msg + endline)
except UnicodeDecodeError:
new_msg = ', '.join(map(meta_util_six.ensure_unicode, args))
return __UTOOL_ROOT_LOGGER__.info(new_msg + endline)
else:
def utool_print(*args):
import utool as ut
utool_flush()
endline = '\n'
__UTOOL_ROOT_LOGGER__.info('\n\n----------')
__UTOOL_ROOT_LOGGER__.info(ut.get_caller_name(range(0, 20)))
return __UTOOL_ROOT_LOGGER__.info(', '.join(map(six.text_type, args)) + endline)
def utool_printdbg(*args):
return __UTOOL_ROOT_LOGGER__.debug(', '.join(map(six.text_type, args)))
__UTOOL_WRITE__ = utool_write
__UTOOL_FLUSH__ = utool_flush
__UTOOL_PRINT__ = utool_print
if VERBOSE or LOGGING_VERBOSE:
__UTOOL_PRINT__('<__LOG_START__>')
__UTOOL_PRINT__(startmsg)
else:
if LOGGING_VERBOSE:
print('[utool] start_logging()... FAILED TO START')
print('DEBUG INFO')
print('__inside_doctest() = %r' % (__inside_doctest(),))
print('__IN_MAIN_PROCESS__ = %r' % (__IN_MAIN_PROCESS__,))
print('__UTOOL_ROOT_LOGGER__ = %r' % (__UTOOL_ROOT_LOGGER__,)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_all_eq_to'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '39']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '22']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'and'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'util_type'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'HAVE_NUMPY'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '36']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '39', 'type': 'try_statement', 'children': ['40', '91']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'with_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'with_clause', 'children': ['43']}, {'id': '43', 'type': 'with_item', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'block', 'children': ['50', '60', '70']}; {'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': 'warnings'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filterwarnings'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'FutureWarning'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '63', 'type': 'list_comprehension', 'children': ['64', '67']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '=='}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'list_comprehension', 'children': ['75', '88']}, {'id': '75', 'type': 'conditional_expression', 'children': ['76', '82', '87'], 'value': 'if'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'__array__'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'flag'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '91', 'type': 'except_clause', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '97', '115']}, {'id': '95', 'type': 'not_operator', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '112']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], 'value': '=='}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '115', 'type': 'else_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'raise_statement', 'children': []} | def list_all_eq_to(list_, val, strict=True):
if util_type.HAVE_NUMPY and isinstance(val, np.ndarray):
return all([np.all(item == val) for item in list_])
try:
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=FutureWarning)
flags = [item == val for item in list_]
return all([np.all(flag) if hasattr(flag, '__array__') else flag
for flag in flags])
except ValueError:
if not strict:
return all([repr(item) == repr(val) for item in list_])
else:
raise |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'isect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'list2'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '16']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'set2'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list2'}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'list1'}; {'id': '22', 'type': 'if_clause', 'children': ['23']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'set2'} | def isect(list1, list2):
r
set2 = set(list2)
return [item for item in list1 if item in set2] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '24', '59']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '17'], 'value': 'and'}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '=='}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '23']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '24', 'type': 'block', 'children': ['25', '31', '42', '53']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'index_list'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value_list'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}, {'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': 'dict_'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sortedby2'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'index_list'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'value_list'}, {'id': '59', 'type': 'else_clause', 'children': ['60']}; {'id': '60', 'type': 'block', 'children': ['61', '76']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'index_list'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sortedby2'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '83']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'index_list'}, {'id': '81', 'type': 'list_splat', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '83', 'type': 'dictionary_splat', 'children': ['84']} | def argsort(*args, **kwargs):
if len(args) == 1 and isinstance(args[0], dict):
dict_ = args[0]
index_list = list(dict_.keys())
value_list = list(dict_.values())
return sortedby2(index_list, value_list)
else:
index_list = list(range(len(args[0])))
return sortedby2(index_list, *args, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'indexable'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '52', '102']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18', '35']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'indexable'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'vk_iter'}; {'id': '22', 'type': 'generator_expression', 'children': ['23', '26']}, {'id': '23', 'type': 'tuple', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'indexable'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'vk_iter'}; {'id': '40', 'type': 'generator_expression', 'children': ['41', '44']}, {'id': '41', 'type': 'tuple', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '44', 'type': 'for_in_clause', 'children': ['45', '48']}, {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'indexable'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56', '73']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '66']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'vk_iter'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '73', 'type': 'else_clause', 'children': ['74']}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '80', 'type': 'for_in_clause', 'children': ['81', '84']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '99']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'vk_iter'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'lambda', 'children': ['91', '93']}, {'id': '91', 'type': 'lambda_parameters', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'vk'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'vk'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'indices'} | def argsort2(indexable, key=None, reverse=False):
if isinstance(indexable, dict):
vk_iter = ((v, k) for k, v in indexable.items())
else:
vk_iter = ((v, k) for k, v in enumerate(indexable))
if key is None:
indices = [k for v, k in sorted(vk_iter, reverse=reverse)]
else:
indices = [k for v, k in sorted(vk_iter, key=lambda vk: key(vk[0]),
reverse=reverse)]
return indices |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'issorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'le'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '14', 'type': 'generator_expression', 'children': ['15', '26']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '21']}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ix'}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ix'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '36'], 'value': '-'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list_'} | def issorted(list_, op=operator.le):
return all(op(list_[ix], list_[ix + 1]) for ix in range(len(list_) - 1)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'depth_profile'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'compress_homogenous'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'compress_consecutive'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_depth'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '20', '38', '42', '60', '158', '211', '353']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'list_'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'}, {'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': 'level_shape_list'}, {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '54']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'util_type'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_listlike'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list_'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64', '66']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '63'], 'value': 'and'}; {'id': '62', 'type': 'False', 'children': []}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'new_depth'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'pass_statement', 'children': []}; {'id': '66', 'type': 'else_clause', 'children': ['67']}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'list_'}, {'id': '71', 'type': 'block', 'children': ['72', '90']}; {'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': 'item'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'item'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'if_statement', 'children': ['91', '97', '149']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'util_type'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'is_listlike'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102', '114']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'depth_profile'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'else_clause', 'children': ['115']}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120', '134']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '>='}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'depth_profile'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '-'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'compress_homogenous'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'if_statement', 'children': ['162', '166']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'allsame'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}; {'id': '166', 'type': 'block', 'children': ['167', '173', '180']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'dim_'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'len_'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}; {'id': '180', 'type': 'if_statement', 'children': ['181', '186', '200']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'dim_'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'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': 'level_shape_list'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '196'], 'value': '+'}; {'id': '194', 'type': 'list', 'children': ['195'], 'value': '[len_]'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'len_'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dim_'}; {'id': '200', 'type': 'else_clause', 'children': ['201']}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'list', 'children': ['209', '210'], 'value': '[len_, dim_]'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'len_'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'dim_'}, {'id': '211', 'type': 'if_statement', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'compress_consecutive'}, {'id': '213', 'type': 'block', 'children': ['214', '229', '237']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'hash_list'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'hash'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'consec_list'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'group_consecutives'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '247']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '243'], 'value': '!='}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'consec_list'}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '247', 'type': 'block', 'children': ['248', '259', '268', '272', '276', '328', '345', '349']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'len_list'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'consec_list'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'cumsum_list'}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'cumsum'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'len_list'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'consec_str'}, {'id': '271', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'thresh'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '276', 'type': 'for_statement', 'children': ['277', '280', '285']}, {'id': '277', 'type': 'pattern_list', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'len_'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'cumsum'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'len_list'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'cumsum_list'}, {'id': '285', 'type': 'block', 'children': ['286', '294']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}, {'id': '291', 'type': 'binary_operator', 'children': ['292', '293'], 'value': '-'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'cumsum'}, {'id': '293', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '298', '317']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': '>'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'len_'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'thresh'}; {'id': '298', 'type': 'block', 'children': ['299', '313']}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'augmented_assignment', 'children': ['301', '302'], 'value': '+='}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'consec_str'}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '309'], 'value': '+'}, {'id': '303', 'type': 'binary_operator', 'children': ['304', '308'], 'value': '+'}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'] * '"}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'len_'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'augmented_assignment', 'children': ['315', '316'], 'value': '+='}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'consec_str'}; {'id': '316', 'type': 'string', 'children': [], 'value': "' + ['"}, {'id': '317', 'type': 'else_clause', 'children': ['318']}; {'id': '318', 'type': 'block', 'children': ['319']}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'augmented_assignment', 'children': ['321', '322'], 'value': '+='}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'consec_str'}; {'id': '322', 'type': 'binary_operator', 'children': ['323', '327'], 'value': '+'}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '327', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '328', 'type': 'if_statement', 'children': ['329', '335']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'consec_str'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '335', 'type': 'block', 'children': ['336']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'consec_str'}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'consec_str'}, {'id': '341', 'type': 'slice', 'children': ['342', '343']}; {'id': '342', 'type': 'colon', 'children': []}, {'id': '343', 'type': 'unary_operator', 'children': ['344'], 'value': '-'}; {'id': '344', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'augmented_assignment', 'children': ['347', '348'], 'value': '+='}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'consec_str'}; {'id': '348', 'type': 'string', 'children': [], 'value': "']'"}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'assignment', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'level_shape_list'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'consec_str'}, {'id': '353', 'type': 'return_statement', 'children': ['354']} | def depth_profile(list_, max_depth=None, compress_homogenous=True, compress_consecutive=False, new_depth=False):
r
if isinstance(list_, dict):
list_ = list(list_.values())
level_shape_list = []
if not any(map(util_type.is_listlike, list_)):
return len(list_)
if False and new_depth:
pass
else:
for item in list_:
if isinstance(item, dict):
item = list(item.values())
if util_type.is_listlike(item):
if max_depth is None:
level_shape_list.append(depth_profile(item, None))
else:
if max_depth >= 0:
level_shape_list.append(depth_profile(item, max_depth - 1))
else:
level_shape_list.append(str(len(item)))
else:
level_shape_list.append(1)
if compress_homogenous:
if allsame(level_shape_list):
dim_ = level_shape_list[0]
len_ = len(level_shape_list)
if isinstance(dim_, tuple):
level_shape_list = tuple([len_] + list(dim_))
else:
level_shape_list = tuple([len_, dim_])
if compress_consecutive:
hash_list = list(map(hash, map(str, level_shape_list)))
consec_list = group_consecutives(hash_list, 0)
if len(consec_list) != len(level_shape_list):
len_list = list(map(len, consec_list))
cumsum_list = np.cumsum(len_list)
consec_str = '['
thresh = 1
for len_, cumsum in zip(len_list, cumsum_list):
value = level_shape_list[cumsum - 1]
if len_ > thresh:
consec_str += str(value) + '] * ' + str(len_)
consec_str += ' + ['
else:
consec_str += str(value) + ', '
if consec_str.endswith(', '):
consec_str = consec_str[:-2]
consec_str += ']'
level_shape_list = consec_str
return level_shape_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_alignment'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'list2'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '15', '22', '48']}; {'id': '10', 'type': 'import_statement', 'children': ['11']}, {'id': '11', 'type': 'aliased_import', 'children': ['12', '14']}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'item1_to_idx'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'make_index_lookup'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'list1'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24', '36']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'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': 'sortx'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict_take'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'item1_to_idx'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'list2'}, {'id': '35', 'type': 'None', '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': 'sortx'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'take'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'item1_to_idx'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'list2'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sortx'} | def list_alignment(list1, list2, missing=False):
import utool as ut
item1_to_idx = make_index_lookup(list1)
if missing:
sortx = ut.dict_take(item1_to_idx, list2, None)
else:
sortx = ut.take(item1_to_idx, list2)
return sortx |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_hasher'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7', '53']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '16', '21', '47']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '12', 'type': 'tuple', 'children': ['13', '14', '15']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'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': 'needs_iteration'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'elif_clause', 'children': ['22', '42']}; {'id': '22', 'type': 'parenthesized_expression', 'children': ['23']}, {'id': '23', 'type': 'boolean_operator', 'children': ['24', '35'], 'value': 'and'}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '28'], 'value': 'and'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'util_type'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'HAVE_NUMPY'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ndarray'}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '41'], 'value': '=='}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'O'"}; {'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': 'needs_iteration'}; {'id': '46', 'type': 'True', 'children': []}, {'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': 'needs_iteration'}; {'id': '52', 'type': 'False', 'children': []}, {'id': '53', 'type': 'if_statement', 'children': ['54', '55', '134']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'needs_iteration'}, {'id': '55', 'type': 'block', 'children': ['56', '60', '64', '71', '78']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'SEP'}, {'id': '59', 'type': 'string', 'children': [], 'value': "b'SEP'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'iter_prefix'}, {'id': '63', 'type': 'string', 'children': [], 'value': "b'ITER'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'iter_'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'iter_prefix'}; {'id': '78', 'type': 'try_statement', 'children': ['79', '108']}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'iter_'}, {'id': '83', 'type': 'block', 'children': ['84', '93', '101']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'pattern_list', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'hashable'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_covert_to_hashable'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'binary_data'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '100'], 'value': '+'}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'SEP'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'hashable'}, {'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': 'hasher'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'binary_data'}; {'id': '108', 'type': 'except_clause', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '110', 'type': 'block', 'children': ['111', '117']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': '_update_hasher'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'hasher'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'iter_'}; {'id': '120', 'type': 'block', 'children': ['121', '128']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'SEP'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_update_hasher'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136', '145', '151']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '141']}; {'id': '138', 'type': 'pattern_list', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'hashable'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_covert_to_hashable'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'binary_data'}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '+'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'hashable'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'binary_data'} | def _update_hasher(hasher, data):
if isinstance(data, (tuple, list, zip)):
needs_iteration = True
elif (util_type.HAVE_NUMPY and isinstance(data, np.ndarray) and
data.dtype.kind == 'O'):
needs_iteration = True
else:
needs_iteration = False
if needs_iteration:
SEP = b'SEP'
iter_prefix = b'ITER'
iter_ = iter(data)
hasher.update(iter_prefix)
try:
for item in iter_:
prefix, hashable = _covert_to_hashable(data)
binary_data = SEP + prefix + hashable
hasher.update(binary_data)
except TypeError:
_update_hasher(hasher, item)
for item in iter_:
hasher.update(SEP)
_update_hasher(hasher, item)
else:
prefix, hashable = _covert_to_hashable(data)
binary_data = prefix + hashable
hasher.update(binary_data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hashlen'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'alphabet'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '23', '32']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'alphabet'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'alphabet'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ALPHABET_27'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'hashlen'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'hashlen'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'HASH_LEN2'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '45', '55']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'and'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'stringlike'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '49', 'type': 'parenthesized_expression', 'children': ['50']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '54'], 'value': '*'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'alphabet'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'hashlen'}, {'id': '55', 'type': 'else_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57', '65', '71', '79', '93', '101']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'hasher'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'hashlib'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sha512'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_update_hasher'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'hasher'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'hasher'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'hexdigest'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'hashstr2'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'convert_hexstr_to_bigbase'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '87']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'alphabet'}, {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'bigbase'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'alphabet'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'hashstr2'}; {'id': '98', 'type': 'slice', 'children': ['99', '100']}, {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'hashlen'}, {'id': '101', 'type': 'return_statement', 'children': ['102']} | def hash_data(data, hashlen=None, alphabet=None):
r
if alphabet is None:
alphabet = ALPHABET_27
if hashlen is None:
hashlen = HASH_LEN2
if isinstance(data, stringlike) and len(data) == 0:
text = (alphabet[0] * hashlen)
else:
hasher = hashlib.sha512()
_update_hasher(hasher, data)
text = hasher.hexdigest()
hashstr2 = convert_hexstr_to_bigbase(text, alphabet, bigbase=len(alphabet))
text = hashstr2[:hashlen]
return text |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'quick_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'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': 'platform'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '42', '49', '90', '99']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '30']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'query_filter'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"name:{0}"'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'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': 'query_filter'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"name:{0},platforms:{1}"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'search_params'}, {'id': '45', 'type': 'dictionary', 'children': ['46']}; {'id': '46', 'type': 'pair', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': '"filter"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'query_filter'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54', '61', '78']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_validate_sort_field'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '63', '70']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'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': 'direction'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'SORT_ORDER_DESCENDING'}; {'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', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'SORT_ORDER_ASCENDING'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '83']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'search_params'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"sort"'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': '"{0}:{1}"'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_query'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'search_params'}, {'id': '99', 'type': 'return_statement', 'children': ['100']} | def quick_search(self, name, platform=None, sort_by=None, desc=True):
if platform is None:
query_filter = "name:{0}".format(name)
else:
query_filter = "name:{0},platforms:{1}".format(name, platform)
search_params = {"filter": query_filter}
if sort_by is not None:
self._validate_sort_field(sort_by)
if desc:
direction = self.SORT_ORDER_DESCENDING
else:
direction = self.SORT_ORDER_ASCENDING
search_params["sort"] = "{0}:{1}".format(sort_by, direction)
response = self._query(search_params)
return response |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'smart_cast'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '36', '151']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '12'], 'value': 'or'}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '18', 'type': 'try_statement', 'children': ['19', '32']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '29']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'issubclass'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '32', 'type': 'except_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'pass_statement', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '41']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'is_str'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46', '52', '87', '110']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'VALID_BOOL_TYPES'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bool_from_str'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '52', 'type': 'elif_clause', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'slice'}; {'id': '56', 'type': 'block', 'children': ['57', '81']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '73']}, {'id': '61', 'type': 'conditional_expression', 'children': ['62', '63', '69'], 'value': 'if'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '68'], 'value': '=='}; {'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': 'arg'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'slice'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'list_splat', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '87', 'type': 'elif_clause', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '91', 'type': 'block', 'children': ['92', '101']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'subvar_list'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "','"}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '107']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'smart_cast2'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'subvar'}, {'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'subvar'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'subvar_list'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '118']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '118', 'type': 'block', 'children': ['119', '129']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'fuzzy_subset'"}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'return_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fuzzy_subset'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133', '141']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '=='}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'eval'"}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'return_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'eval'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '139', 'type': 'dictionary', 'children': []}; {'id': '140', 'type': 'dictionary', 'children': []}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'raise_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'Uknown smart type_=%r'"}, {'id': '149', 'type': 'tuple', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'var'} | def smart_cast(var, type_):
if type_ is None or var is None:
return var
try:
if issubclass(type_, type(None)):
return var
except TypeError:
pass
if is_str(var):
if type_ in VALID_BOOL_TYPES:
return bool_from_str(var)
elif type_ is slice:
args = [None if len(arg) == 0 else int(arg) for arg in var.split(':')]
return slice(*args)
elif type_ is list:
subvar_list = var.split(',')
return [smart_cast2(subvar) for subvar in subvar_list]
elif isinstance(type_, six.string_types):
if type_ == 'fuzzy_subset':
return fuzzy_subset(var)
if type_ == 'eval':
return eval(var, {}, {})
else:
raise NotImplementedError('Uknown smart type_=%r' % (type_,))
return type_(var) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_autogen_code'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'autogen_text'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'codetype'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'python'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fullprint'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'show_diff'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dowrite'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '24', '40', '54', '69', '77', '92', '101', '115', '123', '165']}, {'id': '19', 'type': 'import_statement', 'children': ['20']}; {'id': '20', 'type': 'aliased_import', 'children': ['21', '23']}, {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dowrite'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dowrite'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'tuple', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'-w'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'--write'"}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'show_diff'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'show_diff'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'--diff'"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'num_context_lines'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_argval'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '66']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'--diff'"}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'type_'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'show_diff'}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '74'], 'value': 'or'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'show_diff'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'num_context_lines'}; {'id': '76', 'type': 'None', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'num_context_lines'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'get_argval'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '89']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'--diff'"}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fullprint'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fullprint'}; {'id': '100', 'type': 'True', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fullprint'}; {'id': '104', 'type': 'False', 'children': []}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fullprint'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_argflag'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'--print'"}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'[autogen] Autogenerated %s...\\n+---\\n'"}, {'id': '121', 'type': 'tuple', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '126']}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dowrite'}; {'id': '126', 'type': 'block', 'children': ['127', '153', '158']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '129', '145']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fullprint'}, {'id': '129', 'type': 'block', 'children': ['130', '140']}; {'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': 'ut'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'print_code'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'autogen_text'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'lexer_name'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'codetype'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'\\nL___'"}, {'id': '145', 'type': 'else_clause', 'children': ['146']}; {'id': '146', 'type': 'block', 'children': ['147', '152']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'specify --print to write to stdout'"}; {'id': '152', 'type': 'pass_statement', 'children': []}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'specify -w to write, or --diff to compare'"}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'...would write to: %s'"}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '167', '247']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'show_diff'}, {'id': '167', 'type': 'block', 'children': ['168', '239']}; {'id': '168', 'type': 'if_statement', 'children': ['169', '178']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'checkpath'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '177', 'type': 'True', 'children': []}; {'id': '178', 'type': 'block', 'children': ['179', '188', '201']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'prev_text'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'read_from'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'textdiff'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'get_textdiff'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'prev_text'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'autogen_text'}; {'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'num_context_lines'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'num_context_lines'}, {'id': '201', 'type': 'try_statement', 'children': ['202', '210']}; {'id': '202', 'type': 'block', 'children': ['203']}, {'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': 'ut'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'print_difftext'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'textdiff'}; {'id': '210', 'type': 'except_clause', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '212', 'type': 'block', 'children': ['213', '216', '232']}, {'id': '213', 'type': 'import_statement', 'children': ['214']}; {'id': '214', 'type': 'dotted_name', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'unicodedata'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'textdiff'}, {'id': '219', 'type': 'call', 'children': ['220', '229']}; {'id': '220', 'type': 'attribute', 'children': ['221', '228']}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'unicodedata'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'NFKD'"}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'textdiff'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'print_difftext'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'textdiff'}, {'id': '239', 'type': 'if_statement', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'dowrite'}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'string', 'children': [], 'value': "'WARNING: Not writing. Remove --diff from command line'"}, {'id': '247', 'type': 'elif_clause', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'dowrite'}, {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'write_to'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'fpath'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'autogen_text'} | def dump_autogen_code(fpath, autogen_text, codetype='python', fullprint=None,
show_diff=None, dowrite=None):
import utool as ut
if dowrite is None:
dowrite = ut.get_argflag(('-w', '--write'))
if show_diff is None:
show_diff = ut.get_argflag('--diff')
num_context_lines = ut.get_argval('--diff', type_=int, default=None)
show_diff = show_diff or num_context_lines is not None
num_context_lines = ut.get_argval('--diff', type_=int, default=None)
if fullprint is None:
fullprint = True
if fullprint is False:
fullprint = ut.get_argflag('--print')
print('[autogen] Autogenerated %s...\n+---\n' % (fpath,))
if not dowrite:
if fullprint:
ut.print_code(autogen_text, lexer_name=codetype)
print('\nL___')
else:
print('specify --print to write to stdout')
pass
print('specify -w to write, or --diff to compare')
print('...would write to: %s' % fpath)
if show_diff:
if ut.checkpath(fpath, verbose=True):
prev_text = ut.read_from(fpath)
textdiff = ut.get_textdiff(prev_text, autogen_text,
num_context_lines=num_context_lines)
try:
ut.print_difftext(textdiff)
except UnicodeDecodeError:
import unicodedata
textdiff = unicodedata.normalize('NFKD', textdiff).encode('ascii', 'ignore')
ut.print_difftext(textdiff)
if dowrite:
print('WARNING: Not writing. Remove --diff from command line')
elif dowrite:
ut.write_to(fpath, autogen_text) |
{'id': '0', 'type': 'module', 'children': ['1', '356', '361', '370', '381', '390', '400']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_default_docstr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'with_args'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'with_ret'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'with_commandline'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'with_example'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'with_header'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'with_debug'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '26', '31', '42', '48', '54', '60', '66', '72', '78', '84', '90', '96', '102', '108', '114', '120', '126', '132', '138', '144', '148', '162', '204', '240', '270', '315', '353']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '26', 'type': 'import_statement', 'children': ['27']}, {'id': '27', 'type': 'aliased_import', 'children': ['28', '30']}; {'id': '28', 'type': 'dotted_name', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'utool'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}; {'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': 'ut'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'util_inspect'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'infer_function_info'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'argname_list'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'argname_list'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'argtype_list'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'argtype_list'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'argdesc_list'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'argdesc_list'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'return_header'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'return_header'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'return_type'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'return_type'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'return_name'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'return_name'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'return_desc'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'return_desc'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'num_indent'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'num_indent'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'needs_surround'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'needs_surround'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ismethod'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'va_name'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'va_name'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'kw_name'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'kw_name'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'kw_keys'}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'funcinfo'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'kw_keys'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}, {'id': '147', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'with_header'}; {'id': '150', 'type': 'block', 'children': ['151', '155']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'header_block'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'funcname'}, {'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': 'docstr_parts'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'header_block'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '171']}, {'id': '163', 'type': 'boolean_operator', 'children': ['164', '165'], 'value': 'and'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'with_args'}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '170'], 'value': '>'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'argname_list'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'block', 'children': ['172', '176', '189', '197']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'argheader'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'Args'"}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'arg_docstr'}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'make_args_docstr'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183', '184', '185', '186', '187', '188']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'argname_list'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'argtype_list'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'argdesc_list'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'va_name'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'kw_name'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'kw_keys'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'argsblock'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'make_docstr_block'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'argheader'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'arg_docstr'}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'argsblock'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '210']}, {'id': '205', 'type': 'boolean_operator', 'children': ['206', '207'], 'value': 'and'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'with_ret'}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'is'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'return_header'}, {'id': '209', 'type': 'None', 'children': []}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'if_statement', 'children': ['212', '215']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': 'is'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'return_header'}; {'id': '214', 'type': 'None', 'children': []}, {'id': '215', 'type': 'block', 'children': ['216', '225', '233']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'return_doctr'}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'make_returns_or_yeilds_docstr'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223', '224']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'return_type'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'return_name'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'return_desc'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'returnblock'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'make_docstr_block'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'return_header'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'return_doctr'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'returnblock'}; {'id': '240', 'type': 'if_statement', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'with_commandline'}; {'id': '242', 'type': 'block', 'children': ['243', '247', '255', '263']}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'cmdlineheader'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'CommandLine'"}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'cmdlinecode'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'make_cmdline_docstr'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'cmdlineblock'}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'make_docstr_block'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'cmdlineheader'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'cmdlinecode'}, {'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': 'docstr_parts'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'cmdlineblock'}; {'id': '270', 'type': 'if_statement', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'with_example'}; {'id': '272', 'type': 'block', 'children': ['273', '277', '290', '300', '308']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'exampleheader'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'Example'"}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'examplecode'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'make_example_docstr'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284', '285', '286', '287', '288', '289']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'funcname'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'modname'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'argname_list'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'return_type'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'return_name'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'examplecode_'}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'examplecode'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'>>> '"}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'exampleblock'}, {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'make_docstr_block'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'exampleheader'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'examplecode_'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'exampleblock'}, {'id': '315', 'type': 'if_statement', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'with_debug'}, {'id': '317', 'type': 'block', 'children': ['318', '322', '338', '346']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'debugheader'}, {'id': '321', 'type': 'string', 'children': [], 'value': "'Debug'"}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'assignment', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'debugblock'}, {'id': '325', 'type': 'call', 'children': ['326', '334']}; {'id': '326', 'type': 'attribute', 'children': ['327', '333']}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'codeblock'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'string', 'children': [], 'value': "'''\n num_indent = {num_indent}\n '''"}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'num_indent'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'num_indent'}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}, {'id': '339', 'type': 'assignment', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'debugblock'}, {'id': '341', 'type': 'call', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'make_docstr_block'}, {'id': '343', 'type': 'argument_list', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'debugheader'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'debugblock'}; {'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': 'docstr_parts'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '351', 'type': 'argument_list', 'children': ['352']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'debugblock'}, {'id': '353', 'type': 'if_statement', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'needs_surround'}, {'id': '355', 'type': 'block', 'children': [], 'value': ''}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'assignment', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}, {'id': '359', 'type': 'list', 'children': ['360'], 'value': "['r']"}; {'id': '360', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'default_docstr'}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}, {'id': '371', 'type': 'assignment', 'children': ['372', '373', '375']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'else'}, {'id': '373', 'type': 'type', 'children': ['374']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'default_docstr'}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'string', 'children': [], 'value': "'\\n\\n'"}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'docstr_parts'}, {'id': '381', 'type': 'expression_statement', 'children': ['382']}; {'id': '382', 'type': 'assignment', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'docstr_indent'}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '386'], 'value': '*'}, {'id': '385', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '386', 'type': 'parenthesized_expression', 'children': ['387']}, {'id': '387', 'type': 'binary_operator', 'children': ['388', '389'], 'value': '+'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'num_indent'}, {'id': '389', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '390', 'type': 'expression_statement', 'children': ['391']}, {'id': '391', 'type': 'assignment', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'default_docstr'}, {'id': '393', 'type': 'call', 'children': ['394', '397']}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '397', 'type': 'argument_list', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'default_docstr'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'docstr_indent'}; {'id': '400', 'type': 'return_statement', 'children': ['401']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'default_docstr'} | def make_default_docstr(func, with_args=True, with_ret=True,
with_commandline=True, with_example=True,
with_header=False, with_debug=False):
r
import utool as ut
funcinfo = ut.util_inspect.infer_function_info(func)
argname_list = funcinfo.argname_list
argtype_list = funcinfo.argtype_list
argdesc_list = funcinfo.argdesc_list
return_header = funcinfo.return_header
return_type = funcinfo.return_type
return_name = funcinfo.return_name
return_desc = funcinfo.return_desc
funcname = funcinfo.funcname
modname = funcinfo.modname
defaults = funcinfo.defaults
num_indent = funcinfo.num_indent
needs_surround = funcinfo.needs_surround
funcname = funcinfo.funcname
ismethod = funcinfo.ismethod
va_name = funcinfo.va_name
kw_name = funcinfo.kw_name
kw_keys = funcinfo.kw_keys
docstr_parts = []
if with_header:
header_block = funcname
docstr_parts.append(header_block)
if with_args and len(argname_list) > 0:
argheader = 'Args'
arg_docstr = make_args_docstr(argname_list, argtype_list, argdesc_list,
ismethod, va_name, kw_name, kw_keys)
argsblock = make_docstr_block(argheader, arg_docstr)
docstr_parts.append(argsblock)
if with_ret and return_header is not None:
if return_header is not None:
return_doctr = make_returns_or_yeilds_docstr(return_type, return_name, return_desc)
returnblock = make_docstr_block(return_header, return_doctr)
docstr_parts.append(returnblock)
if with_commandline:
cmdlineheader = 'CommandLine'
cmdlinecode = make_cmdline_docstr(funcname, modname)
cmdlineblock = make_docstr_block(cmdlineheader, cmdlinecode)
docstr_parts.append(cmdlineblock)
if with_example:
exampleheader = 'Example'
examplecode = make_example_docstr(funcname, modname, argname_list,
defaults, return_type, return_name,
ismethod)
examplecode_ = ut.indent(examplecode, '>>> ')
exampleblock = make_docstr_block(exampleheader, examplecode_)
docstr_parts.append(exampleblock)
if with_debug:
debugheader = 'Debug'
debugblock = ut.codeblock(
'''
num_indent = {num_indent}
'''
).format(num_indent=num_indent)
debugblock = make_docstr_block(debugheader, debugblock)
docstr_parts.append(debugblock)
if needs_surround:
docstr_parts = ['r']
default_docstr = '\n'.join(docstr_parts)
else:
default_docstr = '\n\n'.join(docstr_parts)
docstr_indent = ' ' * (num_indent + 4)
default_docstr = ut.indent(default_docstr, docstr_indent)
return default_docstr |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_protein_group'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pgroup'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortfunctions'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortfunc_index'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '21', '25', '65']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pgroup_out'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'subgroups'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sortfunctions'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sortfunc_index'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pgroup'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'augmented_assignment', 'children': ['23', '24'], 'value': '+='}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sortfunc_index'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'subgroup'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'subgroups'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '43', '56']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '37'], 'value': 'and'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '36'], 'value': '>'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'subgroup'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '<'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sortfunc_index'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sortfunctions'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'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': 'pgroup_out'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_protein_group'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'subgroup'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sortfunctions'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sortfunc_index'}; {'id': '56', 'type': 'else_clause', 'children': ['57']}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pgroup_out'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'subgroup'}, {'id': '65', 'type': 'return_statement', 'children': ['66']} | def sort_protein_group(pgroup, sortfunctions, sortfunc_index):
pgroup_out = []
subgroups = sortfunctions[sortfunc_index](pgroup)
sortfunc_index += 1
for subgroup in subgroups:
if len(subgroup) > 1 and sortfunc_index < len(sortfunctions):
pgroup_out.extend(sort_protein_group(subgroup,
sortfunctions,
sortfunc_index))
else:
pgroup_out.extend(subgroup)
return pgroup_out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_amounts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_index'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '42']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'amounts'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'protein'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'proteins'}; {'id': '14', 'type': 'block', 'children': ['15', '21']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'amount_x_for_protein'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort_index'}, {'id': '21', 'type': 'try_statement', 'children': ['22', '32']}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '30']}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'amounts'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'amount_x_for_protein'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '32', 'type': 'except_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'amounts'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'amount_x_for_protein'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': '[protein]'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'list_comprehension', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '49']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '57']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'amounts'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '59', 'type': 'True', 'children': []} | def sort_amounts(proteins, sort_index):
amounts = {}
for protein in proteins:
amount_x_for_protein = protein[sort_index]
try:
amounts[amount_x_for_protein].append(protein)
except KeyError:
amounts[amount_x_for_protein] = [protein]
return [v for k, v in sorted(amounts.items(), reverse=True)] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_groups'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'true_groups'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pred_groups'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '14', '25', '36', '45', '54', '63', '79', '95', '99', '103', '151', '155', '159', '207', '216', '225', '246', '267', '292']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '9', 'type': 'import_statement', 'children': ['10']}; {'id': '10', 'type': 'aliased_import', 'children': ['11', '13']}, {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'true'}, {'id': '17', 'type': 'set_comprehension', 'children': ['18', '22']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_group'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_group'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'true_groups'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '28', 'type': 'set_comprehension', 'children': ['29', '33']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_group'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_group'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pred_groups'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'true'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pred'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'true_sets'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'true'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pred_sets'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pred_conn'}; {'id': '66', 'type': 'dictionary_comprehension', 'children': ['67', '73', '76']}, {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'pred'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'true_conn'}; {'id': '82', 'type': 'dictionary_comprehension', 'children': ['83', '89', '92']}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'true'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'pred_merges'}; {'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': 'true_merges'}; {'id': '102', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'true_sets'}; {'id': '106', 'type': 'block', 'children': ['107', '126']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ccs'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'list_comprehension', 'children': ['114', '123']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pred_conn'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '136']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '135'], 'value': '=='}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'list_splat', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ccs'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '136', 'type': 'block', 'children': ['137', '144']}, {'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': 'pred_merges'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ccs'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'true_merges'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'true_splits'}; {'id': '154', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'pred_splits'}; {'id': '158', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '159', 'type': 'for_statement', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'pred_sets'}; {'id': '162', 'type': 'block', 'children': ['163', '182']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ccs'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'list_comprehension', 'children': ['170', '179']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'true_conn'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '192']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '191'], 'value': '=='}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'list_splat', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ccs'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '192', 'type': 'block', 'children': ['193', '200']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'true_splits'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ccs'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'pred_splits'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'pred_merges_flat'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'pred_merges'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'true_splits_flat'}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'true_splits'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'pred_hybrid'}; {'id': '228', 'type': 'call', 'children': ['229', '239']}, {'id': '229', 'type': 'attribute', 'children': ['230', '238']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'pred_sets'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'pred_splits'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'pred_merges_flat'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'true_hybrid'}, {'id': '249', 'type': 'call', 'children': ['250', '260']}; {'id': '250', 'type': 'attribute', 'children': ['251', '259']}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'frozenset'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'true_sets'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '+'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'true_merges'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'true_splits_flat'}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'comparisons'}; {'id': '270', 'type': 'dictionary', 'children': ['271', '274', '277', '280', '283', '286', '289']}, {'id': '271', 'type': 'pair', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'common'"}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '274', 'type': 'pair', 'children': ['275', '276']}, {'id': '275', 'type': 'string', 'children': [], 'value': "'true_splits'"}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'true_splits'}, {'id': '277', 'type': 'pair', 'children': ['278', '279']}; {'id': '278', 'type': 'string', 'children': [], 'value': "'true_merges'"}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'true_merges'}; {'id': '280', 'type': 'pair', 'children': ['281', '282']}, {'id': '281', 'type': 'string', 'children': [], 'value': "'true_hybrid'"}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'true_hybrid'}, {'id': '283', 'type': 'pair', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'pred_splits'"}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'pred_splits'}; {'id': '286', 'type': 'pair', 'children': ['287', '288']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'pred_merges'"}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'pred_merges'}, {'id': '289', 'type': 'pair', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'pred_hybrid'"}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'pred_hybrid'}; {'id': '292', 'type': 'return_statement', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'comparisons'} | def compare_groups(true_groups, pred_groups):
r
import utool as ut
true = {frozenset(_group) for _group in true_groups}
pred = {frozenset(_group) for _group in pred_groups}
common = true.intersection(pred)
true_sets = true.difference(common)
pred_sets = pred.difference(common)
pred_conn = {p: frozenset(ps) for ps in pred for p in ps}
true_conn = {t: frozenset(ts) for ts in true for t in ts}
pred_merges = []
true_merges = []
for ts in true_sets:
ccs = set([pred_conn.get(t, frozenset()) for t in ts])
if frozenset.union(*ccs) == ts:
pred_merges.append(ccs)
true_merges.append(ts)
true_splits = []
pred_splits = []
for ps in pred_sets:
ccs = set([true_conn.get(p, frozenset()) for p in ps])
if frozenset.union(*ccs) == ps:
true_splits.append(ccs)
pred_splits.append(ps)
pred_merges_flat = ut.flatten(pred_merges)
true_splits_flat = ut.flatten(true_splits)
pred_hybrid = frozenset(map(frozenset, pred_sets)).difference(
set(pred_splits + pred_merges_flat))
true_hybrid = frozenset(map(frozenset, true_sets)).difference(
set(true_merges + true_splits_flat))
comparisons = {
'common': common,
'true_splits': true_splits,
'true_merges': true_merges,
'true_hybrid': true_hybrid,
'pred_splits': pred_splits,
'pred_merges': pred_merges,
'pred_hybrid': pred_hybrid,
}
return comparisons |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'colwise_diag_idxs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '16', '36', '68']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'import_statement', 'children': ['12']}; {'id': '12', 'type': 'aliased_import', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'utool'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'diag_idxs'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ut'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'iprod'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'list_splat', 'children': ['25']}, {'id': '25', 'type': 'list_comprehension', 'children': ['26', '30']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'upper_diag_idxs'}, {'id': '39', 'type': 'list_comprehension', 'children': ['40', '47', '50']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '42', 'type': 'slice', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'colon', 'children': []}; {'id': '44', 'type': 'colon', 'children': []}, {'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'diag_idxs'}; {'id': '50', 'type': 'if_clause', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '>'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '62']}, {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'itertwo'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'upper_diag_idxs'} | def colwise_diag_idxs(size, num=2):
r
import utool as ut
diag_idxs = ut.iprod(*[range(size) for _ in range(num)])
upper_diag_idxs = [
tup[::-1] for tup in diag_idxs
if all([a > b for a, b in ut.itertwo(tup)])
]
return upper_diag_idxs |
Subsets and Splits