sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'commit_check'}, {'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': 'commands'}, {'id': '7', 'type': 'string', 'children': [], 'value': '""'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"text"'}, {'id': '11', 'type': 'block', 'children': ['12', '21', '25', '39', '45', '59', '79', '85', '97', '101', '176']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '15']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'raise_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'InvalidCommandError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'No commands specified'"}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'clean_cmds'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '31']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'clean_lines'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'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': 'clean_cmds'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '52']}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_session'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'load_configuration'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56']}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'set'"}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'clean_cmds'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ET'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'attribute', 'children': ['68', '78']}; {'id': '68', 'type': 'call', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': '_session'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'candidate'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tostring'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'unlock'}; {'id': '84', 'type': 'argument_list', 'children': []}, {'id': '85', 'type': 'if_statement', 'children': ['86', '89']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"xml"'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tostring'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '100', 'type': 'string', 'children': [], 'value': '""'}, {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '108']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'if_statement', 'children': ['110', '115', '120', '152']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': '=='}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'commit-check-success'"}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'augmented_assignment', 'children': ['118', '119'], 'value': '+='}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'configuration check succeeds\\n'"}; {'id': '120', 'type': 'elif_clause', 'children': ['121', '126']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': 'is'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '139']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '138'], 'value': '!='}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '137'], 'value': '+'}; {'id': '130', 'type': 'call', 'children': ['131', '136']}, {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '138', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'augmented_assignment', 'children': ['142', '143'], 'value': '+='}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '151'], 'value': '+'}; {'id': '144', 'type': 'call', 'children': ['145', '150']}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'id': '151', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '152', 'type': 'elif_clause', 'children': ['153', '158']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': 'is'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '157', 'type': 'None', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'if_statement', 'children': ['160', '167']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '166'], 'value': '!='}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '165'], 'value': '+'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '165', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '166', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '176', 'type': 'return_statement', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'out'} | def commit_check(self, commands="", req_format="text"):
if not commands:
raise InvalidCommandError('No commands specified')
clean_cmds = []
for cmd in clean_lines(commands):
clean_cmds.append(cmd)
self.lock()
self._session.load_configuration(action='set', config=clean_cmds)
results = ET.fromstring(self._session.validate(
source='candidate').tostring)
self.unlock()
if req_format == "xml":
return ET.tostring(results)
out = ""
for i in results.iter():
if i.tag == 'commit-check-success':
out += 'configuration check succeeds\n'
elif i.text is not None:
if i.text.strip() + '\n' != '\n':
out += i.text.strip() + '\n'
elif i.text is None:
if i.tag + '\n' != '\n':
out += i.tag + '\n'
return out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '91', '382']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'conn_type'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'paramiko'"}; {'id': '12', 'type': 'block', 'children': ['13', '23', '36', '45', '58']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'paramiko'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'call', 'children': ['27', '34']}, {'id': '27', 'type': 'attribute', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Logger'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'manager'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'paramiko.transport'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'setLevel'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'CRITICAL'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '52']}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_session'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'set_missing_host_key_policy'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'AutoAddPolicy'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'connect'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '71', '76', '81', '86']}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'hostname'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'username'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'connect_timeout'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '97', '191', '242', '333']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'scp'"}, {'id': '97', 'type': 'block', 'children': ['98', '108', '121', '130', '143', '176']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_scp_session'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '111', 'type': 'call', 'children': ['112', '119']}; {'id': '112', 'type': 'attribute', 'children': ['113', '118']}, {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Logger'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'paramiko.transport'"}, {'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': 'logger'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'CRITICAL'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '137']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_scp_session'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'set_missing_host_key_policy'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'paramiko'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'AutoAddPolicy'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '150']}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_scp_session'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '156', '161', '166', '171']}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'hostname'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'username'}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'connect_timeout'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': '_scp'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'SCPClient'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '190']}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_scp_session'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'get_transport'}; {'id': '190', 'type': 'argument_list', 'children': []}, {'id': '191', 'type': 'elif_clause', 'children': ['192', '197']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': '=='}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '196', 'type': 'string', 'children': [], 'value': '"ncclient"'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': '_session'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'connect'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '213', '218', '223', '228', '233', '239']}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'username'}, {'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'connect_timeout'}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'device_params'}, {'id': '235', 'type': 'dictionary', 'children': ['236']}; {'id': '236', 'type': 'pair', 'children': ['237', '238']}, {'id': '237', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '238', 'type': 'string', 'children': [], 'value': "'junos'"}, {'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'hostkey_verify'}, {'id': '241', 'type': 'False', 'children': []}; {'id': '242', 'type': 'elif_clause', 'children': ['243', '248']}, {'id': '243', 'type': 'comparison_operator', 'children': ['244', '247'], 'value': '=='}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'conn_type'}, {'id': '247', 'type': 'string', 'children': [], 'value': "'shell'"}; {'id': '248', 'type': 'block', 'children': ['249', '273', '316']}, {'id': '249', 'type': 'if_statement', 'children': ['250', '254']}; {'id': '250', 'type': 'not_operator', 'children': ['251']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '254', 'type': 'block', 'children': ['255', '261', '267']}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'paramiko'"}, {'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': 'self'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '266', 'type': 'argument_list', 'children': []}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'shell'"}, {'id': '273', 'type': 'if_statement', 'children': ['274', '278']}; {'id': '274', 'type': 'not_operator', 'children': ['275']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': '_shell'}; {'id': '278', 'type': 'block', 'children': ['279', '291', '298']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': '_shell'}; {'id': '284', 'type': 'call', 'children': ['285', '290']}, {'id': '285', 'type': 'attribute', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': '_session'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'invoke_shell'}; {'id': '290', 'type': 'argument_list', 'children': []}, {'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': 'time'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '309']}, {'id': '299', 'type': 'boolean_operator', 'children': ['300', '305'], 'value': 'and'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '304'], 'value': '!='}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '304', 'type': 'string', 'children': [], 'value': "'root'"}, {'id': '305', 'type': 'not_operator', 'children': ['306']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': '_in_cli'}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': '_in_cli'}, {'id': '315', 'type': 'True', 'children': []}; {'id': '316', 'type': 'if_statement', 'children': ['317', '323']}, {'id': '317', 'type': 'not_operator', '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': 'cli_to_shell'}; {'id': '322', 'type': 'argument_list', 'children': []}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '331']}; {'id': '326', 'type': 'attribute', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '_shell'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'recv'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'integer', 'children': [], 'value': '9999'}, {'id': '333', 'type': 'elif_clause', 'children': ['334', '339']}; {'id': '334', 'type': 'comparison_operator', 'children': ['335', '338'], 'value': '=='}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '338', 'type': 'string', 'children': [], 'value': "'root'"}, {'id': '339', 'type': 'block', 'children': ['340', '365']}; {'id': '340', 'type': 'if_statement', 'children': ['341', '345']}, {'id': '341', 'type': 'not_operator', 'children': ['342']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': '_shell'}, {'id': '345', 'type': 'block', 'children': ['346', '358']}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'assignment', 'children': ['348', '351']}; {'id': '348', 'type': 'attribute', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': '_shell'}, {'id': '351', 'type': 'call', 'children': ['352', '357']}; {'id': '352', 'type': 'attribute', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'invoke_shell'}, {'id': '357', 'type': 'argument_list', 'children': []}; {'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': 'time'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '365', 'type': 'if_statement', 'children': ['366', '372']}; {'id': '366', 'type': 'not_operator', 'children': ['367']}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'shell_to_cli'}, {'id': '371', 'type': 'argument_list', 'children': []}; {'id': '372', 'type': 'block', 'children': ['373']}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '380']}, {'id': '375', 'type': 'attribute', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': '_shell'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'recv'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}, {'id': '381', 'type': 'integer', 'children': [], 'value': '9999'}; {'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': 'self'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': '_update_timeout'}, {'id': '387', 'type': 'argument_list', 'children': ['388']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'self'} | def connect(self):
if self.conn_type == 'paramiko':
self._session = paramiko.SSHClient()
logger = logging.Logger.manager.getLogger('paramiko.transport')
logger.setLevel(logging.CRITICAL)
self._session.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
self._session.connect(hostname=self.host,
username=self.username,
password=self.password,
port=self.port,
timeout=self.connect_timeout)
if self.conn_type == 'scp':
self._scp_session = paramiko.SSHClient()
logger = logging.Logger.manager.getLogger('paramiko.transport')
logger.setLevel(logging.CRITICAL)
self._scp_session.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
self._scp_session.connect(hostname=self.host,
username=self.username,
password=self.password,
port=self.port,
timeout=self.connect_timeout)
self._scp = SCPClient(self._scp_session.get_transport())
elif self.conn_type == "ncclient":
self._session = manager.connect(
host=self.host,
port=self.port,
username=self.username,
password=self.password,
timeout=self.connect_timeout,
device_params={'name': 'junos'},
hostkey_verify=False
)
elif self.conn_type == 'shell':
if not self._session:
self.conn_type = 'paramiko'
self.connect()
self.conn_type = 'shell'
if not self._shell:
self._shell = self._session.invoke_shell()
time.sleep(2)
if self.username != 'root' and not self._in_cli:
self._in_cli = True
if not self.cli_to_shell():
self._shell.recv(9999)
elif self.conn_type == 'root':
if not self._shell:
self._shell = self._session.invoke_shell()
time.sleep(2)
if not self.shell_to_cli():
self._shell.recv(9999)
self._update_timeout(self.session_timeout) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'script'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inbox'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '45', '49', '60', '66', '101', '126', '132', '136', '289', '311', '334']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'script_name'}; {'id': '10', 'type': 'subscript', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"id"'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'script_id'}; {'id': '16', 'type': 'subscript', 'children': ['17', '41']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'hash'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '31'], 'value': '+'}, {'id': '27', 'type': 'tuple', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"id"'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'inbox'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'slice', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'colon', 'children': []}; {'id': '44', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '48', 'type': 'dictionary', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"params"'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '59', 'type': 'string', 'children': [], 'value': '"params"'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '65', 'type': 'dictionary', 'children': []}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '71']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'in_port'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'inin_ports'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'inbox'}, {'id': '75', 'type': 'block', 'children': ['76', '86']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'in_path'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'inin_ports'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'in_port'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '91']}, {'id': '87', 'type': 'parenthesized_expression', 'children': ['88'], 'value': '()'}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'in_path'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'block', 'children': ['92', '100']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '98']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"in"'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'in_port'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'in_path'}; {'id': '100', 'type': 'break_statement', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '115']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '109'], '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': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '%'}, {'id': '121', 'type': 'string', 'children': [], 'value': '"not all in_ports connected, got: %s"'}; {'id': '122', 'type': 'tuple', 'children': ['123']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"in"'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"out"'}, {'id': '131', 'type': 'dictionary', 'children': []}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '135', 'type': 'dictionary', 'children': []}; {'id': '136', 'type': 'for_statement', 'children': ['137', '142', '148']}, {'id': '137', 'type': 'pattern_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '139', 'type': 'tuple_pattern', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'out_port'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'out_ext'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"out"'}; {'id': '148', 'type': 'block', 'children': ['149', '242', '275', '283']}, {'id': '149', 'type': 'if_statement', 'children': ['150', '165', '201']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': '=='}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '153', 'type': 'string', 'children': [], 'value': '"in"'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '156', 'type': 'generator_expression', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'out_port_'}; {'id': '158', 'type': 'for_in_clause', 'children': ['159', '162']}, {'id': '159', 'type': 'pattern_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'out_port_'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"out"'}, {'id': '165', 'type': 'block', 'children': ['166', '195']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'pfx'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '194'], 'value': '+'}; {'id': '170', 'type': 'subscript', 'children': ['171', '193']}, {'id': '171', 'type': 'call', 'children': ['172', '191']}; {'id': '172', 'type': 'attribute', 'children': ['173', '190']}, {'id': '173', 'type': 'subscript', 'children': ['174', '188']}; {'id': '174', 'type': 'call', 'children': ['175', '186']}, {'id': '175', 'type': 'attribute', 'children': ['176', '185']}; {'id': '176', 'type': 'subscript', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '179', 'type': 'string', 'children': [], 'value': '"in"'}; {'id': '180', 'type': 'subscript', 'children': ['181', '184']}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '183', 'type': 'string', 'children': [], 'value': '"in"'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '188', 'type': 'unary_operator', 'children': ['189'], 'value': '-'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '194', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '200', 'type': 'string', 'children': [], 'value': '"id"'}, {'id': '201', 'type': 'else_clause', 'children': ['202']}; {'id': '202', 'type': 'block', 'children': ['203', '232']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'pfx'}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '231'], 'value': '+'}, {'id': '207', 'type': 'subscript', 'children': ['208', '230']}; {'id': '208', 'type': 'call', 'children': ['209', '228']}, {'id': '209', 'type': 'attribute', 'children': ['210', '227']}; {'id': '210', 'type': 'subscript', 'children': ['211', '225']}, {'id': '211', 'type': 'call', 'children': ['212', '223']}; {'id': '212', 'type': 'attribute', 'children': ['213', '222']}, {'id': '213', 'type': 'subscript', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '216', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '217', 'type': 'subscript', 'children': ['218', '221']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"in"'}, {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'string', 'children': [], 'value': '"/"'}, {'id': '225', 'type': 'unary_operator', 'children': ['226'], 'value': '-'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '241'], 'value': '+'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '240'], 'value': '+'}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '239', 'type': 'string', 'children': [], 'value': '"id"'}; {'id': '240', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'out_port'}; {'id': '242', 'type': 'if_statement', 'children': ['243', '244', '261']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'out_ext'}; {'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': 'out_path'}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '260'], 'value': '+'}, {'id': '249', 'type': 'binary_operator', 'children': ['250', '259'], 'value': '+'}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '258'], 'value': '+'}, {'id': '251', 'type': 'binary_operator', 'children': ['252', '257'], 'value': '+'}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '256'], 'value': '+'}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '255', 'type': 'string', 'children': [], 'value': '"dir"'}; {'id': '256', 'type': 'string', 'children': [], 'value': '"/"'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'pfx'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '259', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'out_ext'}, {'id': '261', 'type': 'else_clause', 'children': ['262']}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'out_path'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '274'], 'value': '+'}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '273'], 'value': '+'}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '272'], 'value': '+'}, {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '271', 'type': 'string', 'children': [], 'value': '"dir"'}; {'id': '272', 'type': 'string', 'children': [], 'value': '"/"'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'pfx'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '282']}, {'id': '277', 'type': 'subscript', 'children': ['278', '281']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '280', 'type': 'string', 'children': [], 'value': '"out"'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'out_port'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'out_path'}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '288']}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'out_port'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'out_path'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': '_eval_script'}; {'id': '294', 'type': 'argument_list', 'children': ['295', '298', '301', '304', '307', '310']}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '297', 'type': 'string', 'children': [], 'value': '"evaluator"'}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '300', 'type': 'string', 'children': [], 'value': '"preamble"'}, {'id': '301', 'type': 'subscript', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '303', 'type': 'string', 'children': [], 'value': '"dir"'}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '306', 'type': 'string', 'children': [], 'value': '"executable"'}, {'id': '307', 'type': 'subscript', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '309', 'type': 'string', 'children': [], 'value': '"script"'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '311', 'type': 'if_statement', 'children': ['312', '317']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '316'], 'value': '!='}, {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'raise_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '325', '328', '331']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '324', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '327', 'type': 'string', 'children': [], 'value': '"script"'}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '330', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '333', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '334', 'type': 'return_statement', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'out'} | def script(inbox, cfg):
script_name = cfg["id"]
script_id = str(abs(hash((cfg["id"],) + tuple(inbox[0].values()))))[0:8]
args = {}
args["params"] = dict(cfg["params"])
args["in"] = {}
for in_port in cfg["in"]:
for inin_ports in inbox:
in_path = inin_ports.get(in_port, None)
if (in_path is not None):
args["in"][in_port] = in_path
break
if len(args["in"]) < len(cfg["in"]):
raise Exception("not all in_ports connected, got: %s" % (args["in"],))
args["out"] = {}
out = {}
for i, (out_port, out_ext) in enumerate(cfg["out"]):
if cfg["in"] == tuple(out_port_ for out_port_, _ in cfg["out"]):
pfx = args["in"][cfg["in"][i]].split("/")[-1].split(".")[0] + "_"
base = cfg["id"]
else:
pfx = args["in"][cfg["in"][0]].split("/")[-1].split(".")[0] + "_"
base = cfg["id"] + "-" + out_port
if out_ext:
out_path = cfg["dir"] + "/" + pfx + base + "." + out_ext
else:
out_path = cfg["dir"] + "/" + pfx + base
args["out"][out_port] = out_path
out[out_port] = out_path
ret = _eval_script(cfg["evaluator"], cfg["preamble"], cfg["dir"], cfg["executable"], cfg["script"], args)
if ret[0] != 0:
raise Exception(ret[0], cfg["script"], ret[1], ret[2])
return out |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_update_tracking_related_event'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '100']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'related_fields'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_tracked_related_fields'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '36']}, {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '35']}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ManyToManyField'}; {'id': '36', 'type': 'block', 'children': ['37', '74']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '50', '64']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '49']}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ForeignKey'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'{0}_id'"}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'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': 'value'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '82']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '81'], 'value': '!='}; {'id': '76', 'type': 'subscript', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '_original_fields'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'related_field'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'related_fields'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '98']}, {'id': '89', 'type': 'attribute', 'children': ['90', '97']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'related_field'}; {'id': '96', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '100', 'type': 'for_statement', 'children': ['101', '104', '109']}, {'id': '101', 'type': 'pattern_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'related_field'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '108', 'type': 'argument_list', 'children': []}, {'id': '109', 'type': 'block', 'children': ['110', '126', '148']}; {'id': '110', 'type': 'try_statement', 'children': ['111', '122']}, {'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': 'related_instances'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'related_field'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'except_clause', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ObjectDoesNotExist'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'continue_statement', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '132', '141']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'related_instances'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'related_instances'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'related_instances'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'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': 'related_instances'}; {'id': '146', 'type': 'list', 'children': ['147'], 'value': '[related_instances]'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'related_instances'}; {'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'related_instance'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'related_instances'}, {'id': '151', 'type': 'block', 'children': ['152', '160']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_create_event'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'related_instance'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'UPDATE'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '163']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '163', 'type': 'block', 'children': ['164', '176']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'fieldname'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'{0}__{1}'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'related_field'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '_create_tracked_field'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181', '182', '183']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'fieldname'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'fieldname'} | def _create_update_tracking_related_event(instance):
events = {}
for field, related_fields in instance._tracked_related_fields.items():
if not isinstance(instance._meta.get_field(field), ManyToManyField):
if isinstance(instance._meta.get_field(field), ForeignKey):
value = getattr(instance, '{0}_id'.format(field))
else:
value = getattr(instance, field)
if instance._original_fields[field] != value:
for related_field in related_fields:
events.setdefault(related_field, []).append(field)
for related_field, fields in events.items():
try:
related_instances = getattr(instance, related_field[1])
except ObjectDoesNotExist:
continue
if hasattr(related_instances, 'all'):
related_instances = related_instances.all()
else:
related_instances = [related_instances]
for related_instance in related_instances:
event = _create_event(related_instance, UPDATE)
for field in fields:
fieldname = '{0}__{1}'.format(related_field[0], field)
_create_tracked_field(
event, instance, field, fieldname=fieldname
) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '35', '53', '73']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PackageSchema'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '29', 'type': 'tuple', 'children': ['30', '31', '32', '33', '34']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'testlist'"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'extra_cli_args'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'agent_id'"}, {'id': '33', 'type': 'string', 'children': [], 'value': "'options'"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'note'"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48', '49', '50', '51', '52']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ps'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67', '70']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'many'}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '72', 'type': 'True', 'children': []}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ps'} | def list(self, filter=None, type=None, sort=None, limit=None, page=None):
schema = PackageSchema(exclude=('testlist', 'extra_cli_args', 'agent_id', 'options', 'note'))
resp = self.service.list(self.base, filter, type, sort, limit, page)
ps, l = self.service.decode(schema, resp, many=True, links=True)
return Page(ps, l) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_lines'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '5', 'type': 'block', 'children': ['6', '84']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12', '69', '77']}, {'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': 'commands'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '20', '29', '51']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'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': 'commands'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'rb'"}, {'id': '29', 'type': 'elif_clause', 'children': ['30', '41']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '40'], 'value': '>'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "','"}; {'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', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "','"}, {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'try_statement', 'children': ['54', '64', '65']}; {'id': '54', 'type': 'ERROR', 'children': ['55', '62', '63']}, {'id': '55', 'type': 'subscript', 'children': ['56', '61']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"\n yield commands.strip() + \'\\n'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'return'}; {'id': '64', 'type': 'block', 'children': [], 'value': ''}, {'id': '65', 'type': 'except_clause', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'pass_statement', 'children': []}, {'id': '69', 'type': 'elif_clause', 'children': ['70', '75']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'pass_statement', 'children': []}, {'id': '77', 'type': 'else_clause', 'children': ['78']}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'raise_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'clean_lines() accepts a \\'str\\' or \\'list\\''"}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87', '105']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '87', 'type': 'ERROR', 'children': ['88', '104']}; {'id': '88', 'type': 'ERROR', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90', '103']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '102']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '99', '101'], 'value': '!='}; {'id': '92', 'type': 'subscript', 'children': ['93', '98']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'ERROR', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"\n yield cmd.strip() + \'\\n'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '102', 'type': 'block', 'children': [], 'value': ''}, {'id': '103', 'type': 'pass_statement', 'children': []}; {'id': '104', 'type': 'block', 'children': [], 'value': ''}, {'id': '105', 'type': 'block', 'children': [], 'value': ''} | def clean_lines(commands):
if isinstance(commands, basestring):
if path.isfile(commands):
commands = open(commands, 'rb')
elif len(commands.split(',')) > 1:
commands = commands.split(',')
else:
try:
if commands.strip()[0] != "
yield commands.strip() + '\n'
return
except IndexError:
pass
elif isinstance(commands, list):
pass
else:
raise TypeError('clean_lines() accepts a \'str\' or \'list\'')
for cmd in commands:
try:
if cmd.strip()[0] != "
yield cmd.strip() + '\n'
except IndexError:
pass |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'xpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source_xml'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'xpath_expr'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'string'"}, {'id': '9', 'type': 'block', 'children': ['10', '14', '33', '80', '90', '99', '106', '126']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'source_xml'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '23']}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'source_xml'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Element'}, {'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': 'tree'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'objectify'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fromstring'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'source_xml'}, {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '40']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'getiterator'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'id': '49', 'type': 'block', 'children': ['50', '61']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'elem'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'}'"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '>='}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '75', 'type': 'slice', 'children': ['76', '79']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '79', 'type': 'colon', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'objectify'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'deannotate'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cleanup_namespaces'}, {'id': '89', 'type': 'True', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'filtered_list'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'xpath'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'xpath_expr'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'xml'"}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'filtered_list'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "''"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '113', 'type': 'generator_expression', 'children': ['114', '123']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'etree'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tostring'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'pretty_print'}; {'id': '122', 'type': 'True', 'children': []}, {'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'filtered_list'}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'conditional_expression', 'children': ['128', '129', '130'], 'value': 'if'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'matches'} | def xpath(source_xml, xpath_expr, req_format='string'):
tree = source_xml
if not isinstance(source_xml, ET.Element):
tree = objectify.fromstring(source_xml)
for elem in tree.getiterator():
if isinstance(elem.tag, basestring):
i = elem.tag.find('}')
if i >= 0:
elem.tag = elem.tag[i+1:]
objectify.deannotate(tree, cleanup_namespaces=True)
filtered_list = tree.xpath(xpath_expr)
if req_format == 'xml':
return filtered_list
matches = ''.join(etree.tostring(
element, pretty_print=True) for element in filtered_list)
return matches if matches else "" |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'model_to_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '17', '21', '53', '242', '257']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': '"Takes a model instance and converts it into a dict."'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_defaults'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'prehook'"}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '36']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'prehook'"}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'collections'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Callable'}; {'id': '36', 'type': 'block', 'children': ['37', '46']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'prehook'"}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'alias'}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '58', 'type': 'block', 'children': ['59', '71', '79', '91', '104', '236']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'accessor'}; {'id': '62', 'type': 'call', 'children': ['63', '68']}, {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'aliases'"}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'alias'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '+'}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'alias'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'camelcase'"}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'convert_to_camel'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_field_value'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'accessor'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'allow_missing'}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'allow_missing'"}; {'id': '104', 'type': 'if_statement', 'children': ['105', '114']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '109', 'type': 'tuple', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Model'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'QuerySet'}; {'id': '114', 'type': 'block', 'children': ['115', '130', '150']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_defaults'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'related'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'accessor'}, {'id': '129', 'type': 'dictionary', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'%(accessor)s'"}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_options'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_options'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '%'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '_options'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '146', 'type': 'dictionary', 'children': ['147']}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'accessor'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '158', '225']}, {'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': 'value'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'Model'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'if_statement', 'children': ['160', '178', '197']}; {'id': '160', 'type': 'boolean_operator', 'children': ['161', '173', '174'], 'value': 'and'}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '170'], 'value': 'and'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '169'], 'value': '=='}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'fields'"}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'flat'"}, {'id': '173', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '174', 'type': 'not_operator', 'children': ['175']}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': '_options'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'merge'"}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '182', 'type': 'subscript', 'children': ['183', '196']}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '195']}, {'id': '187', 'type': 'attribute', 'children': ['188', '194']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'serialize'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '192', 'type': 'dictionary_splat', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '195', 'type': 'argument_list', 'children': []}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199', '208', '221']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_attrs'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'serialize'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '206', 'type': 'dictionary_splat', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_options'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'merge'"}; {'id': '212', 'type': 'block', 'children': ['213', '220']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_attrs'}; {'id': '220', 'type': 'continue_statement', 'children': []}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': '_attrs'}, {'id': '225', 'type': 'else_clause', 'children': ['226']}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'serialize'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '234', 'type': 'dictionary_splat', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': '_options'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '242', 'type': 'if_statement', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'posthook'"}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'posthook'"}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '257', 'type': 'return_statement', 'children': ['258']} | def model_to_dict(instance, **options):
"Takes a model instance and converts it into a dict."
options = _defaults(options)
attrs = {}
if options['prehook']:
if isinstance(options['prehook'], collections.Callable):
instance = options['prehook'](instance)
if instance is None:
return attrs
for alias in options['fields']:
accessor = options['aliases'].get(alias, alias)
key = options['prefix'] + alias
if options['camelcase']:
key = convert_to_camel(key)
value = get_field_value(instance, accessor,
allow_missing=options['allow_missing'])
if isinstance(value, (models.Model, QuerySet)):
_options = _defaults(options['related'].get(accessor, {}))
if '%(accessor)s' in _options['prefix']:
_options['prefix'] = _options['prefix'] % {'accessor': alias}
if isinstance(value, models.Model):
if len(_options['fields']) == 1 and _options['flat'] \
and not _options['merge']:
value = list(serialize(value, **_options).values())[0]
else:
_attrs = serialize(value, **_options)
if _options['merge']:
attrs.update(_attrs)
continue
value = _attrs
else:
value = serialize(value, **_options)
attrs[key] = value
if options['posthook']:
attrs = options['posthook'](instance, attrs)
return attrs |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '32', '53', '73']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'AttachmentSchema'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '30', 'type': 'parenthesized_expression', 'children': ['31'], 'value': '()'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '48', '49', '50', '51', '52']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_base'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'page'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'at'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67', '70']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'many'}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '72', 'type': 'True', 'children': []}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'at'} | def list(self, id, filter=None, type=None, sort=None, limit=None, page=None):
schema = AttachmentSchema(exclude=('path'))
resp = self.service.list(self._base(id), filter, type, sort, limit, page)
at, l = self.service.decode(schema, resp, many=True, links=True)
return Page(at, l) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_item'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inbox'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"string"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '25', '31', '46', '105', '121', '135', '139', '260', '429', '468']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '21']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'is_file'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'is_fifo'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_socket'}, {'id': '21', 'type': 'expression_list', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'inbox'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'try_statement', 'children': ['32', '39']}; {'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': 'file_type'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '39', 'type': 'except_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"invalid inbox item"'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50', '64', '87', '96']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file_type'}, {'id': '49', 'type': 'string', 'children': [], 'value': '"file"'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'is_file'}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'elif_clause', 'children': ['65', '68']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '=='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'file_type'}, {'id': '67', 'type': 'string', 'children': [], 'value': '"fifo"'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'is_fifo'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'S_ISFIFO'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'attribute', 'children': ['78', '86']}; {'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': 'stat'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'st_mode'}, {'id': '87', 'type': 'elif_clause', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'file_type'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"socket"'}, {'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': 'is_socket'}, {'id': '95', 'type': 'True', 'children': []}; {'id': '96', 'type': 'else_clause', 'children': ['97']}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'raise_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'}, {'id': '103', 'type': 'string', 'children': [], 'value': '"type: %s not undertood"'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'file_type'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '115']}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '111'], 'value': 'and'}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108'], 'value': '()'}; {'id': '108', 'type': 'boolean_operator', 'children': ['109', '110'], 'value': 'or'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'is_fifo'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'is_socket'}, {'id': '111', 'type': 'parenthesized_expression', 'children': ['112'], 'value': '()'}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'mmap'"}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"mmap is not supported for FIFOs and sockets"'}, {'id': '121', 'type': 'if_statement', 'children': ['122', '129']}; {'id': '122', 'type': 'boolean_operator', 'children': ['123', '127'], 'value': 'and'}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124'], 'value': '()'}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '126'], 'value': 'or'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'is_fifo'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'is_socket'}, {'id': '127', 'type': 'not_operator', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'raise_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"FIFOs and sockets have to be removed"'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '143', '182', '247']}; {'id': '140', 'type': 'boolean_operator', 'children': ['141', '142'], 'value': 'or'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'is_fifo'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'is_file'}, {'id': '143', 'type': 'block', 'children': ['144', '159', '173']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '158'], 'value': '-'}; {'id': '148', 'type': 'attribute', 'children': ['149', '157']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'st_size'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '170']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'O_RDONLY'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'BUFFER'}; {'id': '176', 'type': 'parenthesized_expression', 'children': ['177'], 'value': '()'}, {'id': '177', 'type': 'boolean_operator', 'children': ['178', '179'], 'value': 'or'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'PAPY_DEFAULTS'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'PIPE_BUF'"}; {'id': '182', 'type': 'elif_clause', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'is_socket'}; {'id': '184', 'type': 'block', 'children': ['185', '202', '216', '225', '230', '238']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '190']}, {'id': '187', 'type': 'pattern_list', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '190', 'type': 'expression_list', 'children': ['191', '199']}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'gethostbyname'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'sock'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'AF_INET'}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'SOCK_STREAM'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'connect'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'tuple', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '228', 'type': 'unary_operator', 'children': ['229'], 'value': '-'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'fileno'}, {'id': '237', 'type': 'argument_list', 'children': []}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'BUFFER'}, {'id': '241', 'type': 'parenthesized_expression', 'children': ['242'], 'value': '()'}; {'id': '242', 'type': 'boolean_operator', 'children': ['243', '244'], 'value': 'or'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'PAPY_DEFAULTS'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'TCP_RCVBUF'"}, {'id': '247', 'type': 'else_clause', 'children': ['248']}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'raise_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '%'}; {'id': '254', 'type': 'string', 'children': [], 'value': '"got unknown inbox: %s"'}, {'id': '255', 'type': 'parenthesized_expression', 'children': ['256'], 'value': '()'}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'inbox'}; {'id': '260', 'type': 'if_statement', 'children': ['261', '264', '346', '420']}, {'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': '=='}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '263', 'type': 'string', 'children': [], 'value': "'mmap'"}; {'id': '264', 'type': 'block', 'children': ['265', '287', '293', '301', '339']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '-'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '270', 'type': 'parenthesized_expression', 'children': ['271'], 'value': '()'}, {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '%'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '273', 'type': 'parenthesized_expression', 'children': ['274'], 'value': '()'}; {'id': '274', 'type': 'boolean_operator', 'children': ['275', '281', '282'], 'value': 'or'}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '279', '280']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'mmap'}, {'id': '279', 'type': 'string', 'children': [], 'value': "'ALLOCATIONGRANULARITY'"}; {'id': '280', 'type': 'None', 'children': []}, {'id': '281', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'mmap'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'PAGESIZE'"}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '-'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '300'], 'value': '+'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '-'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '301', 'type': 'try_statement', 'children': ['302', '321']}; {'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': 'data'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'mmap'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'mmap'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '312', '313', '318']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'access'}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'mmap'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'ACCESS_READ'}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '321', 'type': 'except_clause', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'mmap'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'mmap'}, {'id': '331', 'type': 'argument_list', 'children': ['332', '333', '334']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'access'}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'mmap'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'ACCESS_READ'}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '346', 'type': 'elif_clause', 'children': ['347', '350']}, {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': '=='}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '349', 'type': 'string', 'children': [], 'value': "'string'"}; {'id': '350', 'type': 'block', 'children': ['351', '355']}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'assignment', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '354', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '355', 'type': 'if_statement', 'children': ['356', '360', '395']}; {'id': '356', 'type': 'comparison_operator', 'children': ['357', '358'], 'value': '=='}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '358', 'type': 'unary_operator', 'children': ['359'], 'value': '-'}, {'id': '359', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '360', 'type': 'block', 'children': ['361', '386']}, {'id': '361', 'type': 'while_statement', 'children': ['362', '363']}; {'id': '362', 'type': 'True', 'children': []}, {'id': '363', 'type': 'block', 'children': ['364', '374', '379']}; {'id': '364', 'type': 'expression_statement', 'children': ['365']}, {'id': '365', 'type': 'assignment', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'buffer_'}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '371', 'type': 'argument_list', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'BUFFER'}; {'id': '374', 'type': 'if_statement', 'children': ['375', '377']}, {'id': '375', 'type': 'not_operator', 'children': ['376']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'buffer_'}, {'id': '377', 'type': 'block', 'children': ['378']}; {'id': '378', 'type': 'break_statement', 'children': []}, {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'call', 'children': ['381', '384']}, {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '384', 'type': 'argument_list', 'children': ['385']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'buffer_'}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'assignment', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '389', 'type': 'call', 'children': ['390', '393']}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}, {'id': '391', 'type': 'string', 'children': [], 'value': '""'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '393', 'type': 'argument_list', 'children': ['394']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '395', 'type': 'else_clause', 'children': ['396']}; {'id': '396', 'type': 'block', 'children': ['397', '406']}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'call', 'children': ['399', '402']}, {'id': '399', 'type': 'attribute', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'lseek'}; {'id': '402', 'type': 'argument_list', 'children': ['403', '404', '405']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '405', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '406', 'type': 'expression_statement', 'children': ['407']}, {'id': '407', 'type': 'assignment', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '409', 'type': 'call', 'children': ['410', '413']}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '413', 'type': 'argument_list', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '415', 'type': 'binary_operator', 'children': ['416', '419'], 'value': '+'}; {'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '-'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '419', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '420', 'type': 'else_clause', 'children': ['421']}, {'id': '421', 'type': 'block', 'children': ['422']}; {'id': '422', 'type': 'raise_statement', 'children': ['423']}, {'id': '423', 'type': 'call', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '425', 'type': 'argument_list', 'children': ['426']}; {'id': '426', 'type': 'binary_operator', 'children': ['427', '428'], 'value': '%'}, {'id': '427', 'type': 'string', 'children': [], 'value': "'type: %s not understood.'"}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '429', 'type': 'if_statement', 'children': ['430', '431', '459']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '431', 'type': 'block', 'children': ['432']}; {'id': '432', 'type': 'if_statement', 'children': ['433', '434', '441']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'is_socket'}; {'id': '434', 'type': 'block', 'children': ['435']}, {'id': '435', 'type': 'expression_statement', 'children': ['436']}; {'id': '436', 'type': 'call', 'children': ['437', '440']}, {'id': '437', 'type': 'attribute', 'children': ['438', '439']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'sock'}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '440', 'type': 'argument_list', 'children': []}, {'id': '441', 'type': 'else_clause', 'children': ['442']}; {'id': '442', 'type': 'block', 'children': ['443', '450']}, {'id': '443', 'type': 'expression_statement', 'children': ['444']}; {'id': '444', 'type': 'call', 'children': ['445', '448']}, {'id': '445', 'type': 'attribute', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '448', 'type': 'argument_list', 'children': ['449']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '450', 'type': 'expression_statement', 'children': ['451']}, {'id': '451', 'type': 'call', 'children': ['452', '455']}; {'id': '452', 'type': 'attribute', 'children': ['453', '454']}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'unlink'}, {'id': '455', 'type': 'argument_list', 'children': ['456']}; {'id': '456', 'type': 'subscript', 'children': ['457', '458']}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '458', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '459', 'type': 'else_clause', 'children': ['460']}; {'id': '460', 'type': 'block', 'children': ['461']}, {'id': '461', 'type': 'expression_statement', 'children': ['462']}; {'id': '462', 'type': 'call', 'children': ['463', '466']}, {'id': '463', 'type': 'attribute', 'children': ['464', '465']}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '465', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '466', 'type': 'argument_list', 'children': ['467']}, {'id': '467', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '468', 'type': 'return_statement', 'children': ['469']}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'data'} | def load_item(inbox, type="string", remove=True, buffer=None):
is_file, is_fifo, is_socket = False, False, False
file = inbox[0]
try:
file_type = file[0]
except:
raise ValueError("invalid inbox item")
if file_type == "file":
is_file = os.path.exists(file[1])
elif file_type == "fifo":
is_fifo = stat.S_ISFIFO(os.stat(file[1]).st_mode)
elif file_type == "socket":
is_socket = True
else:
raise ValueError("type: %s not undertood" % file_type)
if (is_fifo or is_socket) and (type == 'mmap'):
raise ValueError("mmap is not supported for FIFOs and sockets")
if (is_fifo or is_socket) and not remove:
raise ValueError("FIFOs and sockets have to be removed")
start = 0
if is_fifo or is_file:
stop = os.stat(file[1]).st_size - 1
fd = os.open(file[1], os.O_RDONLY)
BUFFER = (buffer or PAPY_DEFAULTS['PIPE_BUF'])
elif is_socket:
host, port = socket.gethostbyname(file[1]), file[2]
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
stop = -1
fd = sock.fileno()
BUFFER = (buffer or PAPY_DEFAULTS['TCP_RCVBUF'])
else:
raise ValueError("got unknown inbox: %s" % (repr(inbox)))
if type == 'mmap':
offset = start - (start % (getattr(mmap, 'ALLOCATIONGRANULARITY', None)\
or getattr(mmap, 'PAGESIZE')))
start = start - offset
stop = stop - offset + 1
try:
data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ, offset=offset)
except TypeError:
data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ)
data.seek(start)
elif type == 'string':
data = []
if stop == -1:
while True:
buffer_ = os.read(fd, BUFFER)
if not buffer_:
break
data.append(buffer_)
data = "".join(data)
else:
os.lseek(fd, start, 0)
data = os.read(fd, stop - start + 1)
else:
raise ValueError('type: %s not understood.' % type)
if remove:
if is_socket:
sock.close()
else:
os.close(fd)
os.unlink(file[1])
else:
os.close(fd)
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_validate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14', '82']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': '!='}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'tuple', 'children': ['12', '13']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"default"'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"default"'}; {'id': '14', 'type': 'block', 'children': ['15', '43', '68']}, {'id': '15', 'type': 'try_statement', 'children': ['16', '29']}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'pattern_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dest_file'}; {'id': '22', 'type': 'tuple', 'children': ['23', '26']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '29', 'type': 'except_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'BadParameter'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'concatenated_string', 'children': ['39', '40', '41', '42']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'Expecting two arguments, one for how to '"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'output (s, single, m, multiple), and '"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'the second is a filepath where to put'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "' the output.'"}, {'id': '43', 'type': 'if_statement', 'children': ['44', '55']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '50'], 'value': 'not'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'list', 'children': ['51', '52', '53', '54'], 'value': "['s', 'single', 'm', 'multiple']"}, {'id': '51', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'single'"}, {'id': '53', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '54', 'type': 'string', 'children': [], 'value': "'multiple'"}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'raise_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'BadParameter'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'concatenated_string', 'children': ['63', '64', '65', '66', '67']}, {'id': '63', 'type': 'string', 'children': [], 'value': "'The first argument of the -w/--write '"}; {'id': '64', 'type': 'string', 'children': [], 'value': "'option must specifies whether to write'"}, {'id': '65', 'type': 'string', 'children': [], 'value': "' to one file per device, or all device'"}; {'id': '66', 'type': 'string', 'children': [], 'value': "' output to a single file. Valid options'"}, {'id': '67', 'type': 'string', 'children': [], 'value': '\' are "s", "single", "m", and "multiple"\''}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'out'"}, {'id': '75', 'type': 'tuple', 'children': ['76', '81']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dest_file'}; {'id': '82', 'type': 'else_clause', 'children': ['83']}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'out'"}, {'id': '91', 'type': 'None', 'children': []} | def write_validate(ctx, param, value):
if value != ("default", "default"):
try:
mode, dest_file = (value[0], value[1])
except IndexError:
raise click.BadParameter('Expecting two arguments, one for how to '
'output (s, single, m, multiple), and '
'the second is a filepath where to put'
' the output.')
if mode.lower() not in ['s', 'single', 'm', 'multiple']:
raise click.BadParameter('The first argument of the -w/--write '
'option must specifies whether to write'
' to one file per device, or all device'
' output to a single file. Valid options'
' are "s", "single", "m", and "multiple"')
ctx.obj['out'] = (mode.lower(), dest_file)
else:
ctx.obj['out'] = None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_out'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input'}, {'id': '5', 'type': 'block', 'children': ['6', '12']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'to_file'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '!='}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'to_file'}, {'id': '15', 'type': 'string', 'children': [], 'value': '"quiet"'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'try_statement', 'children': ['18', '25', '35']}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dest_file'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'to_file'}, {'id': '25', 'type': 'except_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37', '59', '94']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '40', 'type': 'call', 'children': ['41', '58']}, {'id': '41', 'type': 'attribute', 'children': ['42', '57']}; {'id': '42', 'type': 'subscript', 'children': ['43', '56']}, {'id': '43', 'type': 'call', 'children': ['44', '54']}; {'id': '44', 'type': 'attribute', 'children': ['45', '53']}, {'id': '45', 'type': 'subscript', 'children': ['46', '52']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'device: '"}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '65']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '62', 'type': 'list', 'children': ['63', '64'], 'value': "['m', 'multiple']"}, {'id': '63', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '64', 'type': 'string', 'children': [], 'value': "'multiple'"}, {'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': 'dest_file'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '82']}; {'id': '74', 'type': 'subscript', 'children': ['75', '81']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'dest_file'}, {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '86'], 'value': '+'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '86', 'type': 'subscript', 'children': ['87', '93']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dest_file'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'try_statement', 'children': ['95', '104', '139']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'out_file'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dest_file'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'a+b'"}; {'id': '104', 'type': 'except_clause', 'children': ['105', '109']}, {'id': '105', 'type': 'as_pattern', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '107', 'type': 'as_pattern_target', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '109', 'type': 'block', 'children': ['110', '125']}; {'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': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '124']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '121'], 'value': '%'}; {'id': '118', 'type': 'concatenated_string', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': '"Could not open output file \'%s\' for writing. "'}; {'id': '120', 'type': 'string', 'children': [], 'value': '"Output would have been:\\n%s"'}, {'id': '121', 'type': 'tuple', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dest_file'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'red'"}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '138']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'Here is the error for opening the output file:'"}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'red'"}, {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141', '154', '166']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'click'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '151']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '150', 'type': 'False', 'children': []}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'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': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'%s output appended to: %s'"}, {'id': '163', 'type': 'tuple', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'dest_file'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'out_file'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '171', 'type': 'argument_list', 'children': []} | def write_out(input):
to_file, output = input
if to_file != "quiet":
try:
mode, dest_file = to_file
except TypeError:
click.echo(output)
else:
ip = output.split('device: ')[1].split('\n')[0].strip()
if mode in ['m', 'multiple']:
dest_file = path.join(path.split(dest_file)[0], ip + "_" +
path.split(dest_file)[1])
try:
out_file = open(dest_file, 'a+b')
except IOError as e:
print(color("Could not open output file '%s' for writing. "
"Output would have been:\n%s" %
(dest_file, output), 'red'))
print(color('Here is the error for opening the output file:' +
str(e), 'red'))
else:
click.echo(output, nl=False, file=out_file)
print(color('%s output appended to: %s' % (ip, dest_file)))
out_file.close() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'endpoint'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '52', '79', '110', '134', '157', '168', '177', '202', '229', '246', '288', '316']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '!='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'raise_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Http404'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'BOUNCY_TOPIC_ARN'"}, {'id': '21', 'type': 'block', 'children': ['22', '34']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '28']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'not'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'HTTP_X_AMZ_SNS_TOPIC_ARN'"}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'META'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'No TopicArn Header'"}; {'id': '34', 'type': 'if_statement', 'children': ['35', '46']}, {'id': '35', 'type': 'parenthesized_expression', 'children': ['36'], 'value': '()'}; {'id': '36', 'type': 'not_operator', 'children': ['37']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': 'in'}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'META'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'HTTP_X_AMZ_SNS_TOPIC_ARN'"}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'BOUNCY_TOPIC_ARN'}; {'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': 'HttpResponseBadRequest'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'Bad Topic'"}; {'id': '52', 'type': 'if_statement', 'children': ['53', '60', '67']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'request_body'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'request_body'}; {'id': '72', 'type': 'call', 'children': ['73', '78']}, {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'try_statement', 'children': ['80', '90']}; {'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': 'json'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'request_body'}; {'id': '90', 'type': 'except_clause', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '92', 'type': 'block', 'children': ['93', '105']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'Notification Not Valid JSON: {}'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'request_body'}, {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'Not Valid JSON'"}; {'id': '110', 'type': 'if_statement', 'children': ['111', '121']}, {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '<='}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'VITAL_NOTIFICATION_FIELDS'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '121', 'type': 'block', 'children': ['122', '129']}; {'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': 'logger'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'Request Missing Necessary Keys'"}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'string', 'children': [], 'value': "'Request Missing Necessary Keys'"}; {'id': '134', 'type': 'if_statement', 'children': ['135', '141']}, {'id': '135', 'type': 'not_operator', 'children': ['136']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': 'in'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_TYPES'}, {'id': '141', 'type': 'block', 'children': ['142', '152']}; {'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': 'logger'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'Notification Type Not Known %s'"}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '152', 'type': 'return_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'Unknown Notification Type'"}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '160', 'type': 'attribute', 'children': ['161', '167']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'SigningCertURL'"}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'BOUNCY_CERT_DOMAIN_REGEX'"}; {'id': '176', 'type': 'string', 'children': [], 'value': 'r"sns.[a-z0-9\\-]+.amazonaws.com$"'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '186']}; {'id': '178', 'type': 'not_operator', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '186', 'type': 'block', 'children': ['187', '197']}, {'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': 'logger'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'Improper Certificate Location %s'"}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'SigningCertURL'"}, {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'string', 'children': [], 'value': "'Improper Certificate Location'"}; {'id': '202', 'type': 'if_statement', 'children': ['203', '216']}, {'id': '203', 'type': 'parenthesized_expression', 'children': ['204'], 'value': '()'}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '211'], 'value': 'and'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'BOUNCY_VERIFY_CERTIFICATE'"}; {'id': '210', 'type': 'True', 'children': []}, {'id': '211', 'type': 'not_operator', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'verify_notification'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '216', 'type': 'block', 'children': ['217', '224']}, {'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': 'logger'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'string', 'children': [], 'value': "'Verification Failure %s'"}; {'id': '224', 'type': 'return_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'string', 'children': [], 'value': "'Improper Signature'"}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '236']}, {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'signals'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '240', '243']}, {'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sender'}, {'id': '239', 'type': 'string', 'children': [], 'value': "'bouncy_endpoint'"}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '246', 'type': 'if_statement', 'children': ['247', '252', '269']}, {'id': '247', 'type': 'comparison_operator', 'children': ['248', '251'], 'value': '=='}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'Type'"}, {'id': '251', 'type': 'string', 'children': [], 'value': "'SubscriptionConfirmation'"}; {'id': '252', 'type': 'block', 'children': ['253', '264']}, {'id': '253', 'type': 'if_statement', 'children': ['254', '261']}; {'id': '254', 'type': 'not_operator', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '257', 'type': 'argument_list', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '259', 'type': 'string', 'children': [], 'value': "'BOUNCY_AUTO_SUBSCRIBE'"}; {'id': '260', 'type': 'True', 'children': []}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'raise_statement', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'Http404'}; {'id': '264', 'type': 'return_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'approve_subscription'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '269', 'type': 'elif_clause', 'children': ['270', '275']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '274'], 'value': '=='}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '273', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '274', 'type': 'string', 'children': [], 'value': "'UnsubscribeConfirmation'"}, {'id': '275', 'type': 'block', 'children': ['276', '283']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'string', 'children': [], 'value': "'UnsubscribeConfirmation Not Handled'"}, {'id': '283', 'type': 'return_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'UnsubscribeConfirmation Not Handled'"}; {'id': '288', 'type': 'try_statement', 'children': ['289', '301']}, {'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': 'message'}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'loads'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '300', 'type': 'string', 'children': [], 'value': "'Message'"}, {'id': '301', 'type': 'except_clause', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '303', 'type': 'block', 'children': ['304', '311']}; {'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': 'logger'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'string', 'children': [], 'value': "'Non-Valid JSON Message Received'"}, {'id': '311', 'type': 'return_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}, {'id': '315', 'type': 'string', 'children': [], 'value': "'Message is not valid JSON'"}; {'id': '316', 'type': 'return_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'process_message'}, {'id': '319', 'type': 'argument_list', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'data'} | def endpoint(request):
if request.method != 'POST':
raise Http404
if hasattr(settings, 'BOUNCY_TOPIC_ARN'):
if 'HTTP_X_AMZ_SNS_TOPIC_ARN' not in request.META:
return HttpResponseBadRequest('No TopicArn Header')
if (not request.META['HTTP_X_AMZ_SNS_TOPIC_ARN']
in settings.BOUNCY_TOPIC_ARN):
return HttpResponseBadRequest('Bad Topic')
if isinstance(request.body, str):
request_body = request.body
else:
request_body = request.body.decode()
try:
data = json.loads(request_body)
except ValueError:
logger.warning('Notification Not Valid JSON: {}'.format(request_body))
return HttpResponseBadRequest('Not Valid JSON')
if not set(VITAL_NOTIFICATION_FIELDS) <= set(data):
logger.warning('Request Missing Necessary Keys')
return HttpResponseBadRequest('Request Missing Necessary Keys')
if not data['Type'] in ALLOWED_TYPES:
logger.info('Notification Type Not Known %s', data['Type'])
return HttpResponseBadRequest('Unknown Notification Type')
domain = urlparse(data['SigningCertURL']).netloc
pattern = getattr(
settings, 'BOUNCY_CERT_DOMAIN_REGEX', r"sns.[a-z0-9\-]+.amazonaws.com$"
)
if not re.search(pattern, domain):
logger.warning(
'Improper Certificate Location %s', data['SigningCertURL'])
return HttpResponseBadRequest('Improper Certificate Location')
if (getattr(settings, 'BOUNCY_VERIFY_CERTIFICATE', True)
and not verify_notification(data)):
logger.error('Verification Failure %s', )
return HttpResponseBadRequest('Improper Signature')
signals.notification.send(
sender='bouncy_endpoint', notification=data, request=request)
if data['Type'] == 'SubscriptionConfirmation':
if not getattr(settings, 'BOUNCY_AUTO_SUBSCRIBE', True):
raise Http404
return approve_subscription(data)
elif data['Type'] == 'UnsubscribeConfirmation':
logger.info('UnsubscribeConfirmation Not Handled')
return HttpResponse('UnsubscribeConfirmation Not Handled')
try:
message = json.loads(data['Message'])
except ValueError:
logger.info('Non-Valid JSON Message Received')
return HttpResponse('Message is not valid JSON')
return process_message(message, data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_value'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '7', 'type': 'block', 'children': ['8', '30']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '20']}, {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '18'], 'value': '+'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '18', 'type': 'tuple', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'value'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'value'} | def _process_value(self, value, type):
if not isinstance(value, six.string_types + (list,)):
value = json.dumps(value)
return value |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'representatives'}, {'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': 'count'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '16', '33', '48', '58', '69', '88']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_process_value'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'int'"}, {'id': '33', 'type': 'if_statement', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'sorting'"}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_process_value'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'strbool'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'call'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'representatives'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'representatives'}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '68'], 'value': 'or'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'representatives'"}; {'id': '68', 'type': 'dictionary', 'children': []}, {'id': '69', 'type': 'for_statement', 'children': ['70', '73', '78']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'representatives'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'representatives'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'representatives'} | def representatives(self, count=None, sorting=False):
payload = {}
if count is not None:
payload['count'] = self._process_value(count, 'int')
if sorting:
payload['sorting'] = self._process_value(sorting, 'strbool')
resp = self.call('representatives', payload)
representatives = resp.get('representatives') or {}
for k, v in representatives.items():
representatives[k] = int(v)
return representatives |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterative_overlap_assembly'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_overlap_size'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '26', '33', '40', '49', '57']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': '<='}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'n_before_collapse'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'collapse_substrings'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'n_after_collapse'}; {'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': 'variant_sequences'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Collapsed %d -> %d sequences"'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'n_before_collapse'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'n_after_collapse'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'merged_variant_sequences'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'greedy_merge'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'variant_sequences'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'min_overlap_size'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'merged_variant_sequences'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '67', 'type': 'lambda', 'children': ['68', '70']}; {'id': '68', 'type': 'lambda_parameters', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '70', 'type': 'unary_operator', 'children': ['71'], 'value': '-'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'seq'} | def iterative_overlap_assembly(
variant_sequences,
min_overlap_size=MIN_VARIANT_SEQUENCE_ASSEMBLY_OVERLAP_SIZE):
if len(variant_sequences) <= 1:
return variant_sequences
n_before_collapse = len(variant_sequences)
variant_sequences = collapse_substrings(variant_sequences)
n_after_collapse = len(variant_sequences)
logger.info(
"Collapsed %d -> %d sequences",
n_before_collapse,
n_after_collapse)
merged_variant_sequences = greedy_merge(variant_sequences, min_overlap_size)
return list(sorted(
merged_variant_sequences,
key=lambda seq: -len(seq.reads))) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ortho_basis'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'normal'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '21', '28', '35', '42', '46', '62', '77', '88', '205', '215', '226', '236', '247']}, {'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': 'numpy'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '17']}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '17', 'type': 'aliased_import', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '21', 'type': 'import_from_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '24', 'type': 'aliased_import', 'children': ['25', '27']}, {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sprnd'}; {'id': '28', 'type': 'import_from_statement', 'children': ['29', '33']}, {'id': '29', 'type': 'relative_import', 'children': ['30', '31']}; {'id': '30', 'type': 'import_prefix', 'children': []}, {'id': '31', 'type': 'dotted_name', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '33', 'type': 'dotted_name', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '35', 'type': 'import_from_statement', 'children': ['36', '40']}; {'id': '36', 'type': 'relative_import', 'children': ['37', '38']}, {'id': '37', 'type': 'import_prefix', 'children': []}; {'id': '38', 'type': 'dotted_name', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '40', 'type': 'dotted_name', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'VectorError'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'RAND_MAG'}, {'id': '45', 'type': 'float', 'children': [], 'value': '0.25'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '56']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '55'], 'value': '=='}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'normal'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"\'normal\' is not a vector"'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '71']}, {'id': '63', 'type': 'not_operator', 'children': ['64']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '70'], 'value': '=='}, {'id': '65', 'type': 'subscript', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'normal'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'raise_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"Length of \'normal\' is not three"'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '/'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'normal'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'normal'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92', '145']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93', '97', '126', '134']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'nv'}, {'id': '97', 'type': 'while_statement', 'children': ['98', '103']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'parallel_check'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'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': 'rv'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'float64'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '116'], 'value': '+'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '-'}; {'id': '114', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'RAND_MAG'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '120'], 'value': '*'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '*'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'RAND_MAG'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sprnd'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'rand'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'rej'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '/'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '145', 'type': 'else_clause', 'children': ['146']}; {'id': '146', 'type': 'block', 'children': ['147', '163', '178', '189']}, {'id': '147', 'type': 'if_statement', 'children': ['148', '157']}; {'id': '148', 'type': 'not_operator', 'children': ['149']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '156'], 'value': '=='}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'raise_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"ref_vec is not a vector"'}, {'id': '163', 'type': 'if_statement', 'children': ['164', '172']}; {'id': '164', 'type': 'not_operator', 'children': ['165']}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '171'], 'value': '=='}; {'id': '166', 'type': 'subscript', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'raise_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'string', 'children': [], 'value': '"ref_vec length is not three"'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '/'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ref_vec'}, {'id': '189', 'type': 'if_statement', 'children': ['190', '195']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'parallel_check'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'raise_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'VectorError'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '203', '204']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'VectorError'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'NONPRL'}, {'id': '203', 'type': 'string', 'children': [], 'value': '"\'normal\' and \'ref_vec\' are too nearly parallel."'}; {'id': '204', 'type': 'string', 'children': [], 'value': '""'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'on2'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'cross'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'rv'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'on2'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '/'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'on2'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'on2'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'on1'}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cross'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'on2'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'on1'}, {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '/'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'on1'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'on1'}, {'id': '247', 'type': 'return_statement', 'children': ['248']}; {'id': '248', 'type': 'expression_list', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'on1'} | def ortho_basis(normal, ref_vec=None):
import numpy as np
from scipy import linalg as spla
from scipy import random as sprnd
from ..const import PRM
from ..error import VectorError
RAND_MAG = 0.25
if not len(normal.shape) == 1:
raise ValueError("'normal' is not a vector")
if not normal.shape[0] == 3:
raise ValueError("Length of 'normal' is not three")
nv = normal / spla.norm(normal)
if ref_vec is None:
rv = nv
while parallel_check(nv, rv):
rv = np.float64(1.0 - RAND_MAG + 2 * RAND_MAG * sprnd.rand(3))
rv = rej(rv, nv)
rv = rv / spla.norm(rv)
else:
if not len(ref_vec.shape) == 1:
raise ValueError("ref_vec is not a vector")
if not ref_vec.shape[0] == 3:
raise ValueError("ref_vec length is not three")
rv = ref_vec / spla.norm(ref_vec)
if parallel_check(nv, rv):
raise VectorError(VectorError.NONPRL,
"'normal' and 'ref_vec' are too nearly parallel.", "")
on2 = np.cross(nv, rv)
on2 = on2 / spla.norm(on2)
on1 = np.cross(on2, nv)
on1 = on1 / spla.norm(on1)
return on1, on2 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'orthonorm_check'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'tol'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': '_DEF'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ORTHONORM_TOL'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'report'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '19', '26', '30', '34', '38', '80', '94', '179']}; {'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': 'numpy'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']}; {'id': '20', 'type': 'relative_import', 'children': ['21', '22']}, {'id': '21', 'type': 'import_prefix', 'children': []}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'delta_fxn'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'orth'}, {'id': '29', 'type': 'True', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'n_fail'}, {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'o_fail'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '47', '64']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '46'], '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': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a_mx'}, {'id': '51', 'type': 'attribute', 'children': ['52', '63']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'float_'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'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': 'a_mx'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'matrix'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'float_'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'a_split'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'hsplit'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'a_mx'}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'a_mx'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '104']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'iter1'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'a_mx'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '116']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'iter2'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'iter1'}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'a_mx'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'if_statement', 'children': ['118', '148']}; {'id': '118', 'type': 'not_operator', 'children': ['119']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '147'], 'value': '<='}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'binary_operator', 'children': ['124', '137'], 'value': '-'}; {'id': '124', 'type': 'subscript', 'children': ['125', '135', '136']}, {'id': '125', 'type': 'parenthesized_expression', 'children': ['126'], 'value': '()'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '132'], 'value': '*'}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'a_split'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'iter1'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'a_split'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'iter2'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'float_'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'delta_fxn'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'iter1'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'iter2'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'tol'}; {'id': '148', 'type': 'block', 'children': ['149', '153']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'orth'}; {'id': '152', 'type': 'False', 'children': []}, {'id': '153', 'type': 'if_statement', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'report'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160', '168']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '=='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'iter1'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'iter2'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'n_fail'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'iter1'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'o_fail'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'tuple', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'iter1'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'iter2'}, {'id': '179', 'type': 'if_statement', 'children': ['180', '181', '187']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'report'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'return_statement', 'children': ['183']}, {'id': '183', 'type': 'expression_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'orth'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'n_fail'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'o_fail'}, {'id': '187', 'type': 'else_clause', 'children': ['188']}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'expression_list', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'orth'}; {'id': '192', 'type': 'None', 'children': []}, {'id': '193', 'type': 'None', 'children': []} | def orthonorm_check(a, tol=_DEF.ORTHONORM_TOL, report=False):
import numpy as np
from .base import delta_fxn
orth = True
n_fail = []
o_fail = []
if len(a.shape) == 1:
a_mx = np.matrix(a, dtype=np.float_).T
else:
a_mx = np.matrix(a, dtype=np.float_)
a_split = np.hsplit(a_mx, a_mx.shape[1])
for iter1 in range(a_mx.shape[1]):
for iter2 in range(iter1,a_mx.shape[1]):
if not abs((a_split[iter1].T * a_split[iter2])[0,0] -
np.float_(delta_fxn(iter1, iter2))) <= tol:
orth = False
if report:
if iter1 == iter2:
n_fail.append(iter1)
else:
o_fail.append((iter1, iter2))
if report:
return orth, n_fail, o_fail
else:
return orth, None, None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parallel_check'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '19', '23', '51', '70', '78', '102']}, {'id': '7', 'type': 'import_from_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'relative_import', 'children': ['9', '10']}, {'id': '9', 'type': 'import_prefix', 'children': []}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'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': 'numpy'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '27', '33']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'list', 'children': ['31', '32'], 'value': '[vec1, vec2]'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'vec2'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '44', '50']}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '43'], 'value': '=='}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'ERROR', 'children': ['45', '46', '48', '49']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '46', 'type': 'ERROR', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'Bad'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'vector'}; {'id': '50', 'type': 'block', 'children': [], 'value': ''}, {'id': '51', 'type': 'if_statement', 'children': ['52', '64']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '59'], 'value': '=='}; {'id': '54', 'type': 'subscript', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"Vector length mismatch"'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'angle'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'vec_angle'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '97']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '94'], 'value': '<'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'list', 'children': ['84', '88'], 'value': '[abs(angle), abs(angle - 180.)]'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'angle'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '-'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'angle'}, {'id': '93', 'type': 'float', 'children': [], 'value': '180.'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'NON_PARALLEL_TOL'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'par'}, {'id': '101', 'type': 'True', 'children': []}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'par'} | def parallel_check(vec1, vec2):
from ..const import PRM
import numpy as np
par = False
for n,v in enumerate([vec1, vec2]):
if not len(v.shape) == 1:
raise ValueError("Bad shape for vector
if not vec1.shape[0] == vec2.shape[0]:
raise ValueError("Vector length mismatch")
angle = vec_angle(vec1, vec2)
if min([abs(angle), abs(angle - 180.)]) < PRM.NON_PARALLEL_TOL:
par = True
return par |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'vec_angle'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '19', '26', '41', '56', '74', '91', '108', '132', '167']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']}; {'id': '20', 'type': 'relative_import', 'children': ['21', '22']}, {'id': '21', 'type': 'import_prefix', 'children': []}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '35']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '34'], 'value': '!='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"\'vec1\' is not a vector"'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '50']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '49'], 'value': '!='}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"\'vec2\' is not a vector"'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '68']}, {'id': '57', 'type': 'comparison_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': 'vec1'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'subscript', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'raise_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"Vector lengths are not equal"'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '85']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '82'], 'value': '<'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'raise_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"\'vec1\' norm is too small"'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '102']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '99'], 'value': '<'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'vec2'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'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': 'ValueError'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'string', 'children': [], 'value': '"\'vec2\' norm is too small"'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'dotp'}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '126'], 'value': '/'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '120'], 'value': '/'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'vec1'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'vec1'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'vec2'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136', '141', '151']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '>'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dotp'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'angle'}; {'id': '140', 'type': 'float', 'children': [], 'value': '0.'}, {'id': '141', 'type': 'elif_clause', 'children': ['142', '146']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '<'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dotp'}; {'id': '144', 'type': 'unary_operator', 'children': ['145'], 'value': '-'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'angle'}; {'id': '150', 'type': 'float', 'children': [], 'value': '180.'}, {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'angle'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'degrees'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'arccos'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dotp'}, {'id': '167', 'type': 'return_statement', 'children': ['168']} | def vec_angle(vec1, vec2):
import numpy as np
from scipy import linalg as spla
from ..const import PRM
if len(vec1.shape) != 1:
raise ValueError("'vec1' is not a vector")
if len(vec2.shape) != 1:
raise ValueError("'vec2' is not a vector")
if vec1.shape[0] != vec2.shape[0]:
raise ValueError("Vector lengths are not equal")
if spla.norm(vec1) < PRM.ZERO_VEC_TOL:
raise ValueError("'vec1' norm is too small")
if spla.norm(vec2) < PRM.ZERO_VEC_TOL:
raise ValueError("'vec2' norm is too small")
dotp = np.dot(vec1, vec2) / spla.norm(vec1) / spla.norm(vec2)
if dotp > 1:
angle = 0.
elif dotp < -1:
angle = 180.
else:
angle = np.degrees(np.arccos(dotp))
return angle |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ctr_mass'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '21', '36', '51', '68', '100', '124', '168']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '17']}, {'id': '13', 'type': 'relative_import', 'children': ['14', '15']}; {'id': '14', 'type': 'import_prefix', 'children': []}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '17', 'type': 'aliased_import', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'safe_cast'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'scast'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '30']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '29'], 'value': '!='}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'raise_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"Geometry is not a vector"'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '45']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '44'], 'value': '!='}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'raise_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"Masses cannot be parsed as a vector"'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '62']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '61'], 'value': '=='}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '60'], 'value': '%'}, {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'ValueError'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"Geometry is not length-3N"'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '94']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '83'], 'value': 'and'}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '76'], 'value': '!='}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '*'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '78', 'type': 'subscript', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '89'], 'value': '!='}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'raise_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Inconsistent geometry and masses vector lengths"'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '114']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '107'], 'value': '=='}; {'id': '102', 'type': 'subscript', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '*'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ctr'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '160'], 'value': '/'}; {'id': '128', 'type': 'call', 'children': ['129', '159']}, {'id': '129', 'type': 'attribute', 'children': ['130', '158']}; {'id': '130', 'type': 'call', 'children': ['131', '154']}, {'id': '131', 'type': 'attribute', 'children': ['132', '152', '153']}; {'id': '132', 'type': 'call', 'children': ['133', '142']}, {'id': '133', 'type': 'attribute', 'children': ['134', '141']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'multiply'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'tuple', 'children': ['144', '151']}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '150'], 'value': '//'}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '152', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'squeeze'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'parenthesized_expression', 'children': ['161'], 'value': '()'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '167'], 'value': '/'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '166', 'type': 'argument_list', 'children': []}, {'id': '167', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '168', 'type': 'return_statement', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ctr'} | def ctr_mass(geom, masses):
import numpy as np
from .base import safe_cast as scast
if len(geom.shape) != 1:
raise ValueError("Geometry is not a vector")
if len(masses.shape) != 1:
raise ValueError("Masses cannot be parsed as a vector")
if not geom.shape[0] % 3 == 0:
raise ValueError("Geometry is not length-3N")
if geom.shape[0] != 3*masses.shape[0] and geom.shape[0] != masses.shape[0]:
raise ValueError("Inconsistent geometry and masses vector lengths")
if geom.shape[0] == 3*masses.shape[0]:
masses = masses.repeat(3)
ctr = np.multiply(geom, masses).reshape((geom.shape[0]//3, 3)) \
.sum(axis=0).squeeze() / (masses.sum() / 3)
return ctr |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inertia_tensor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '20', '44', '55', '247']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ctr_geom'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '34']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '27'], 'value': '=='}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '*'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '29', 'type': 'subscript', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'masses'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tensor'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'tuple', 'children': ['53', '54']}, {'id': '53', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '61']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '69']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74', '150']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '74', 'type': 'block', 'children': ['75', '124']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'list_comprehension', 'children': ['84', '112']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '111'], 'value': '+'}, {'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': 'array'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '102']}; {'id': '96', 'type': 'lambda', 'children': ['97', '99']}, {'id': '97', 'type': 'lambda_parameters', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '108']}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '123']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '130']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '130', 'type': 'call', 'children': ['131', '149']}, {'id': '131', 'type': 'attribute', 'children': ['132', '148']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'multiply'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '145']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'square'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'else_clause', 'children': ['151']}, {'id': '151', 'type': 'block', 'children': ['152', '172', '192', '237']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ind_i'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164', '171']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'binary_operator', 'children': ['165', '170'], 'value': '+'}, {'id': '165', 'type': 'subscript', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ind_j'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184', '191']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '190'], 'value': '+'}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '198']}; {'id': '194', 'type': 'subscript', 'children': ['195', '196', '197']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tensor'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '198', 'type': 'binary_operator', 'children': ['199', '235'], 'value': '*'}, {'id': '199', 'type': 'call', 'children': ['200', '234']}; {'id': '200', 'type': 'attribute', 'children': ['201', '233']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'multiply'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '222']}; {'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': 'sqrt'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'multiply'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ind_i'}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'masses'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'ind_j'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'multiply'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '230']}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ind_i'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ind_j'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '234', 'type': 'argument_list', 'children': []}, {'id': '235', 'type': 'unary_operator', 'children': ['236'], 'value': '-'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '243']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'tensor'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '243', 'type': 'subscript', 'children': ['244', '245', '246']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'tensor'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '247', 'type': 'return_statement', 'children': ['248']} | def inertia_tensor(geom, masses):
import numpy as np
geom = ctr_geom(geom, masses)
if geom.shape[0] == 3*masses.shape[0]:
masses = masses.repeat(3)
tensor = np.zeros((3,3))
for i in range(3):
for j in range(i,3):
if i == j:
ind = np.concatenate([np.array(list(map(lambda v: v % 3,
range(i+1, i+3)))) + o for o in
range(0,geom.shape[0],3)])
tensor[i,i] = np.multiply(np.square(geom[ind]),
masses[ind]).sum()
else:
ind_i = np.array(range(i,geom.shape[0]+i,3))
ind_j = np.array(range(j,geom.shape[0]+j,3))
tensor[i,j] = np.multiply(
np.sqrt(np.multiply(masses[ind_i], masses[ind_j])) ,
np.multiply(geom[ind_i], geom[ind_j]) ).sum() * -1
tensor[j,i] = tensor[i,j]
return tensor |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rot_consts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': '_EURC'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'INV_INERTIA'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'on_tol'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_DEF'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ORTHONORM_TOL'}; {'id': '16', 'type': 'block', 'children': ['17', '22', '39', '55', '67', '101', '336']}, {'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': 'numpy'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '22', 'type': 'import_from_statement', 'children': ['23', '27', '31', '35', '37']}, {'id': '23', 'type': 'relative_import', 'children': ['24', '25']}; {'id': '24', 'type': 'import_prefix', 'children': []}, {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '27', 'type': 'aliased_import', 'children': ['28', '30']}; {'id': '28', 'type': 'dotted_name', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'EnumTopType'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ETT'}, {'id': '31', 'type': 'aliased_import', 'children': ['32', '34']}; {'id': '32', 'type': 'dotted_name', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'EnumUnitsRotConst'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'EURC'}, {'id': '35', 'type': 'dotted_name', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '37', 'type': 'dotted_name', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '44']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'units'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"\'{0}\' is not a valid units value"'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'units'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '61']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'principals'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'masses'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'on_tol'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '73', '86']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ETT'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ATOM'}, {'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': 'mom'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'repeat'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ZERO_MOMENT_TOL'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '86', 'type': 'elif_clause', 'children': ['87', '92']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ETT'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'LINEAR'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '98']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ZERO_MOMENT_TOL'}, {'id': '101', 'type': 'if_statement', 'children': ['102', '107', '117', '139', '165', '191', '222', '255', '289', '329']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '=='}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'INV_INERTIA'}, {'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': 'rc'}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '/'}; {'id': '112', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '113', 'type': 'parenthesized_expression', 'children': ['114'], 'value': '()'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '*'}, {'id': '115', 'type': 'float', 'children': [], 'value': '2.0'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '117', 'type': 'elif_clause', 'children': ['118', '123']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ANGFREQ_ATOMIC'}, {'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': 'rc'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '131'], 'value': '/'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'PLANCK_BAR'}, {'id': '131', 'type': 'parenthesized_expression', 'children': ['132'], 'value': '()'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '*'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '*'}; {'id': '134', 'type': 'float', 'children': [], 'value': '2.0'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'mom'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}, {'id': '139', 'type': 'elif_clause', 'children': ['140', '145']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ANGFREQ_SECS'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '162'], 'value': '/'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '154'], 'value': '/'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'PLANCK_BAR'}; {'id': '154', 'type': 'parenthesized_expression', 'children': ['155'], 'value': '()'}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '159'], 'value': '*'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '*'}, {'id': '157', 'type': 'float', 'children': [], 'value': '2.0'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'SEC_PER_TA'}, {'id': '165', 'type': 'elif_clause', 'children': ['166', '171']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '=='}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'CYCFREQ_ATOMIC'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '179'], 'value': '/'}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'PLANCK_BAR'}, {'id': '179', 'type': 'parenthesized_expression', 'children': ['180'], 'value': '()'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '188'], 'value': '*'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '187'], 'value': '*'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '*'}, {'id': '183', 'type': 'float', 'children': [], 'value': '4.0'}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'mom'}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}, {'id': '191', 'type': 'elif_clause', 'children': ['192', '197']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'CYCFREQ_HZ'}, {'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': 'rc'}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '218', '219'], 'value': '/'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '206'], 'value': '/'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'PLANCK_BAR'}; {'id': '206', 'type': 'parenthesized_expression', 'children': ['207'], 'value': '()'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '215'], 'value': '*'}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '214'], 'value': '*'}, {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '*'}; {'id': '210', 'type': 'float', 'children': [], 'value': '4.0'}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}; {'id': '218', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'SEC_PER_TA'}; {'id': '222', 'type': 'elif_clause', 'children': ['223', '228']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': '=='}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'units'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'EURC'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'CYCFREQ_MHZ'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '254'], 'value': '/'}, {'id': '233', 'type': 'binary_operator', 'children': ['234', '250', '251'], 'value': '/'}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '/'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'PLANCK_BAR'}; {'id': '238', 'type': 'parenthesized_expression', 'children': ['239'], 'value': '()'}, {'id': '239', 'type': 'binary_operator', 'children': ['240', '247'], 'value': '*'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '246'], 'value': '*'}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '*'}; {'id': '242', 'type': 'float', 'children': [], 'value': '4.0'}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}; {'id': '250', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'SEC_PER_TA'}; {'id': '254', 'type': 'float', 'children': [], 'value': '1.0e6'}, {'id': '255', 'type': 'elif_clause', 'children': ['256', '261']}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': '=='}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'WAVENUM_ATOMIC'}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '265', 'type': 'binary_operator', 'children': ['266', '276', '277'], 'value': '/'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '270'], 'value': '/'}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'PLANCK'}; {'id': '270', 'type': 'parenthesized_expression', 'children': ['271'], 'value': '()'}, {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '*'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'mom'}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}; {'id': '276', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '277', 'type': 'parenthesized_expression', 'children': ['278'], 'value': '()'}; {'id': '278', 'type': 'binary_operator', 'children': ['279', '286'], 'value': '*'}, {'id': '279', 'type': 'binary_operator', 'children': ['280', '281'], 'value': '*'}; {'id': '280', 'type': 'float', 'children': [], 'value': '8.0'}, {'id': '281', 'type': 'binary_operator', 'children': ['282', '285'], 'value': '**'}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '285', 'type': 'float', 'children': [], 'value': '2.0'}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'LIGHT_SPEED'}, {'id': '289', 'type': 'elif_clause', 'children': ['290', '295']}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '292'], 'value': '=='}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'EURC'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'WAVENUM_CM'}, {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '328'], 'value': '*'}; {'id': '300', 'type': 'binary_operator', 'children': ['301', '311', '312'], 'value': '/'}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '305'], 'value': '/'}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'PLANCK'}, {'id': '305', 'type': 'parenthesized_expression', 'children': ['306'], 'value': '()'}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '*'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'mom'}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'ME_PER_AMU'}, {'id': '311', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '312', 'type': 'parenthesized_expression', 'children': ['313'], 'value': '()'}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '325'], 'value': '*'}; {'id': '314', 'type': 'binary_operator', 'children': ['315', '322'], 'value': '*'}, {'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '*'}; {'id': '316', 'type': 'float', 'children': [], 'value': '8.0'}, {'id': '317', 'type': 'binary_operator', 'children': ['318', '321'], 'value': '**'}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '321', 'type': 'float', 'children': [], 'value': '2.0'}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'PHYS'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'LIGHT_SPEED'}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'ANG_PER_BOHR'}; {'id': '328', 'type': 'float', 'children': [], 'value': '1.0e8'}, {'id': '329', 'type': 'else_clause', 'children': ['330']}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'raise_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'string', 'children': [], 'value': '"Units conversion not yet implemented."'}; {'id': '336', 'type': 'return_statement', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'rc'} | def rot_consts(geom, masses, units=_EURC.INV_INERTIA, on_tol=_DEF.ORTHONORM_TOL):
import numpy as np
from ..const import EnumTopType as ETT, EnumUnitsRotConst as EURC, PRM, PHYS
if not units in EURC:
raise ValueError("'{0}' is not a valid units value".format(units))
mom, ax, top = principals(geom, masses, on_tol)
if top == ETT.ATOM:
mom = np.repeat(PRM.ZERO_MOMENT_TOL, 3)
elif top == ETT.LINEAR:
mom[0] = PRM.ZERO_MOMENT_TOL
if units == EURC.INV_INERTIA:
rc = 1.0 / (2.0 * mom)
elif units == EURC.ANGFREQ_ATOMIC:
rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU)
elif units == EURC.ANGFREQ_SECS:
rc = PHYS.PLANCK_BAR / (2.0 * mom * PHYS.ME_PER_AMU) / PHYS.SEC_PER_TA
elif units == EURC.CYCFREQ_ATOMIC:
rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU)
elif units == EURC.CYCFREQ_HZ:
rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \
PHYS.SEC_PER_TA
elif units == EURC.CYCFREQ_MHZ:
rc = PHYS.PLANCK_BAR / (4.0 * np.pi * mom * PHYS.ME_PER_AMU) / \
PHYS.SEC_PER_TA / 1.0e6
elif units == EURC.WAVENUM_ATOMIC:
rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \
(8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED)
elif units == EURC.WAVENUM_CM:
rc = PHYS.PLANCK / (mom * PHYS.ME_PER_AMU) / \
(8.0 * np.pi**2.0 * PHYS.LIGHT_SPEED * PHYS.ANG_PER_BOHR) * 1.0e8
else:
raise NotImplementedError("Units conversion not yet implemented.")
return rc |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_fadn_orth'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '19', '26', '33', '42', '69', '83', '100', '111']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']}; {'id': '20', 'type': 'relative_import', 'children': ['21', '22']}, {'id': '21', 'type': 'import_prefix', 'children': []}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '26', 'type': 'import_from_statement', 'children': ['27', '31']}, {'id': '27', 'type': 'relative_import', 'children': ['28', '29']}; {'id': '28', 'type': 'import_prefix', 'children': []}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '31', 'type': 'dotted_name', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}, {'id': '33', 'type': 'import_from_statement', 'children': ['34', '38']}; {'id': '34', 'type': 'relative_import', 'children': ['35', '36']}, {'id': '35', 'type': 'import_prefix', 'children': []}; {'id': '36', 'type': 'dotted_name', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'vector'}; {'id': '38', 'type': 'aliased_import', 'children': ['39', '41']}, {'id': '39', 'type': 'dotted_name', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'orthonorm_check'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'onchk'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '63']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'parenthesized_expression', 'children': ['45'], 'value': '()'}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '54'], 'value': 'and'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '53'], 'value': '=='}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '62'], 'value': '=='}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '61'], 'value': '%'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'raise_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Geometry is not length 3N"'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '77']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '=='}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'vec'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '75', 'type': 'tuple', 'children': ['76']}; {'id': '76', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'raise_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'string', 'children': [], 'value': '"Reference vector is not length 3"'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '94']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '91'], 'value': '<'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'raise_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Reference vector norm is too small"'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '/'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '111', 'type': 'for_statement', 'children': ['112', '113', '127', '182']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'tuple', 'children': ['119', '126']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '125'], 'value': '//'}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '168']}, {'id': '129', 'type': 'boolean_operator', 'children': ['130', '140'], 'value': 'and'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '137'], 'value': '>='}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'id': '140', 'type': 'not_operator', 'children': ['141']}, {'id': '141', 'type': 'subscript', 'children': ['142', '167']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'onchk'}; {'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': 'np'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'column_stack'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'tuple', 'children': ['151', '159']}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '/'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '/'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'block', 'children': ['169', '180']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'out_vec'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '/'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'out_vec'}; {'id': '182', 'type': 'else_clause', 'children': ['183']}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'raise_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '191', '192']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'BAD_GEOM'}, {'id': '191', 'type': 'string', 'children': [], 'value': '"No suitable atomic displacement found"'} | def _fadn_orth(vec, geom):
import numpy as np
from scipy import linalg as spla
from ..const import PRM
from ..error import InertiaError
from .vector import orthonorm_check as onchk
if not (len(geom.shape) == 1 and geom.shape[0] % 3 == 0):
raise ValueError("Geometry is not length 3N")
if not vec.shape == (3,):
raise ValueError("Reference vector is not length 3")
if spla.norm(vec) < PRM.ZERO_VEC_TOL:
raise ValueError("Reference vector norm is too small")
vec = vec / spla.norm(vec)
for disp in geom.reshape((geom.shape[0]//3, 3)):
if spla.norm(disp) >= PRM.ZERO_VEC_TOL and not onchk(
np.column_stack((disp / spla.norm(disp),
vec / spla.norm(vec))))[0]:
out_vec = disp / spla.norm(disp)
return out_vec
else:
raise InertiaError(InertiaError.BAD_GEOM,
"No suitable atomic displacement found", "") |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_fadn_par'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '19', '26', '33', '42', '69', '83', '100', '111', '176']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']}; {'id': '20', 'type': 'relative_import', 'children': ['21', '22']}, {'id': '21', 'type': 'import_prefix', 'children': []}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '26', 'type': 'import_from_statement', 'children': ['27', '31']}, {'id': '27', 'type': 'relative_import', 'children': ['28', '29']}; {'id': '28', 'type': 'import_prefix', 'children': []}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '31', 'type': 'dotted_name', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}, {'id': '33', 'type': 'import_from_statement', 'children': ['34', '38']}; {'id': '34', 'type': 'relative_import', 'children': ['35', '36']}, {'id': '35', 'type': 'import_prefix', 'children': []}; {'id': '36', 'type': 'dotted_name', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'vector'}; {'id': '38', 'type': 'aliased_import', 'children': ['39', '41']}, {'id': '39', 'type': 'dotted_name', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'parallel_check'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'parchk'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '63']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'parenthesized_expression', 'children': ['45'], 'value': '()'}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '54'], 'value': 'and'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '53'], 'value': '=='}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '62'], 'value': '=='}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '61'], 'value': '%'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'raise_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Geometry is not length 3N"'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '77']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '=='}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'vec'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '75', 'type': 'tuple', 'children': ['76']}; {'id': '76', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'raise_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'string', 'children': [], 'value': '"Reference vector is not length 3"'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '94']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '91'], 'value': '<'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'raise_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Reference vector norm is too small"'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '/'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'vec'}, {'id': '111', 'type': 'for_statement', 'children': ['112', '113', '127', '165']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'tuple', 'children': ['119', '126']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '125'], 'value': '//'}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '152']}, {'id': '129', 'type': 'boolean_operator', 'children': ['130', '140', '141'], 'value': 'and'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '137'], 'value': '>='}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'disp'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'id': '140', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '141', 'type': 'not_operator', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'parchk'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '151']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'vec'}; {'id': '152', 'type': 'block', 'children': ['153', '164']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'out_vec'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '/'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'disp'}; {'id': '164', 'type': 'break_statement', 'children': []}, {'id': '165', 'type': 'else_clause', 'children': ['166']}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'raise_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '174', '175']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'InertiaError'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'BAD_GEOM'}; {'id': '174', 'type': 'string', 'children': [], 'value': '"Linear molecule, no non-parallel displacement"'}, {'id': '175', 'type': 'string', 'children': [], 'value': '""'}; {'id': '176', 'type': 'return_statement', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'out_vec'} | def _fadn_par(vec, geom):
import numpy as np
from scipy import linalg as spla
from ..const import PRM
from ..error import InertiaError
from .vector import parallel_check as parchk
if not (len(geom.shape) == 1 and geom.shape[0] % 3 == 0):
raise ValueError("Geometry is not length 3N")
if not vec.shape == (3,):
raise ValueError("Reference vector is not length 3")
if spla.norm(vec) < PRM.ZERO_VEC_TOL:
raise ValueError("Reference vector norm is too small")
vec = vec / spla.norm(vec)
for disp in geom.reshape((geom.shape[0]//3, 3)):
if spla.norm(disp) >= PRM.ZERO_VEC_TOL and \
not parchk(disp.reshape(3), vec):
out_vec = disp / spla.norm(disp)
break
else:
raise InertiaError(InertiaError.BAD_GEOM,
"Linear molecule, no non-parallel displacement", "")
return out_vec |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reference_contexts_for_variants'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variants'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'context_size'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '37']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'variants'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reference_contexts_for_variant'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '31', '34']}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'context_size'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'context_size'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}, {'id': '37', 'type': 'return_statement', 'children': ['38']} | def reference_contexts_for_variants(
variants,
context_size,
transcript_id_whitelist=None):
result = OrderedDict()
for variant in variants:
result[variant] = reference_contexts_for_variant(
variant=variant,
context_size=context_size,
transcript_id_whitelist=transcript_id_whitelist)
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pack_tups'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '16', '21', '26', '39', '54', '73', '91', '98', '121', '129', '162', '175']}, {'id': '7', 'type': 'import_statement', 'children': ['8']}; {'id': '8', 'type': 'aliased_import', 'children': ['9', '11']}, {'id': '9', 'type': 'dotted_name', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'NOT_ITER'}, {'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '-'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'UNINIT_VAL'}; {'id': '24', 'type': 'unary_operator', 'children': ['25'], 'value': '-'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'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': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"args = {0}"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '39', 'type': 'class_definition', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'StrNoIter'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'function_definition', 'children': ['45', '46', '48']}, {'id': '45', 'type': 'function_name', 'children': [], 'value': '__iter__'}; {'id': '46', 'type': 'parameters', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'raise_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"Non-iterable string"'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'mod_args'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '70']}; {'id': '58', 'type': 'parenthesized_expression', 'children': ['59'], 'value': '()'}, {'id': '59', 'type': 'conditional_expression', 'children': ['60', '64', '69'], 'value': 'if'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'StrNoIter'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'a'}; {'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': 'a'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'iterlens'}; {'id': '76', 'type': 'list_comprehension', 'children': ['77', '88']}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'conditional_expression', 'children': ['79', '83', '87'], 'value': 'if'}, {'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': 'a'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'NOT_ITER'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'mod_args'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'maxiter'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'iterlens'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '115']}, {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '114']}; {'id': '106', 'type': 'lambda', 'children': ['107', '109']}, {'id': '107', 'type': 'lambda_parameters', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '111', 'type': 'tuple', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'NOT_ITER'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'maxiter'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'iterlens'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"All iterable items must be of equal length"'}, {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'maxiter'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'NOT_ITER'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'list', 'children': ['128'], 'value': '[args]'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'list_splat', 'children': ['139']}, {'id': '139', 'type': 'list_comprehension', 'children': ['140', '153']}; {'id': '140', 'type': 'parenthesized_expression', 'children': ['141'], 'value': '()'}, {'id': '141', 'type': 'conditional_expression', 'children': ['142', '149', '152'], 'value': 'if'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'maxiter'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '=='}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'NOT_ITER'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '153', 'type': 'for_in_clause', 'children': ['154', '157']}; {'id': '154', 'type': 'tuple_pattern', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'mod_args'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'iterlens'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': '"tups = {0}"'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '175', 'type': 'return_statement', 'children': ['176']} | def pack_tups(*args):
import numpy as np
_DEBUG = False
NOT_ITER = -1
UNINIT_VAL = -1
if _DEBUG:
print("args = {0}".format(args))
class StrNoIter(str):
def __iter__(self):
raise NotImplementedError("Non-iterable string")
mod_args = [(StrNoIter(a) if isinstance(a, str) else a) for a in args]
iterlens = [(len(a) if iterable(a) else NOT_ITER) for a in mod_args]
maxiter = max(iterlens)
if not all(map(lambda v: v in (NOT_ITER, maxiter), iterlens)):
raise ValueError("All iterable items must be of equal length")
if maxiter == NOT_ITER:
return [args]
tups = list(zip(*[(np.repeat(a, maxiter) if l == NOT_ITER else a)
for (a,l) in zip(mod_args, iterlens)]))
if _DEBUG:
print("tups = {0}".format(tups))
return tups |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_geom'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'c1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'a1'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'c2'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'a2'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tol'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_DEF'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'XYZ_COORD_MATCH_TOL'}, {'id': '13', 'type': 'block', 'children': ['14', '21', '26', '35', '39', '56', '73', '90', '107', '128', '149', '178', '199', '226', '257', '288', '298', '325']}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '19']}, {'id': '15', 'type': 'relative_import', 'children': ['16', '17']}; {'id': '16', 'type': 'import_prefix', 'children': []}, {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'atom_num'}, {'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': 'numpy'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '26', 'type': 'import_from_statement', 'children': ['27', '31']}, {'id': '27', 'type': 'relative_import', 'children': ['28', '29']}; {'id': '28', 'type': 'import_prefix', 'children': []}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '31', 'type': 'aliased_import', 'children': ['32', '34']}; {'id': '32', 'type': 'dotted_name', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'EnumCheckGeomMismatch'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ECGM'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '38', 'type': 'True', 'children': []}, {'id': '39', 'type': 'if_statement', 'children': ['40', '49']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '48'], 'value': '=='}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'c1'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'parenthesized_expression', 'children': ['55'], 'value': '()'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"\'c1\' is not a vector."'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '66']}, {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '65'], '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': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'c2'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'raise_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'parenthesized_expression', 'children': ['72'], 'value': '()'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"\'c2\' is not a vector."'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '83']}; {'id': '74', 'type': 'not_operator', 'children': ['75']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '82'], 'value': '=='}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'raise_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'parenthesized_expression', 'children': ['89'], 'value': '()'}, {'id': '89', 'type': 'string', 'children': [], 'value': '"\'a1\' is not a simple list."'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '100']}, {'id': '91', 'type': 'not_operator', 'children': ['92']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '99'], 'value': '=='}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'a2'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'parenthesized_expression', 'children': ['106'], 'value': '()'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"\'a2\' is not a simple list."'}, {'id': '107', 'type': 'if_statement', 'children': ['108', '122']}; {'id': '108', 'type': 'not_operator', 'children': ['109']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '115'], 'value': '=='}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'c1'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '*'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'a1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'raise_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'string', 'children': [], 'value': '"len(c1) != 3*len(a1)"'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '143']}, {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '136'], 'value': '=='}, {'id': '131', 'type': 'subscript', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'c2'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '*'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'raise_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"len(c2) != 3*len(a2)"'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '162']}; {'id': '150', 'type': 'not_operator', 'children': ['151']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '157'], 'value': '=='}; {'id': '152', 'type': 'subscript', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'c1'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'c2'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '162', 'type': 'block', 'children': ['163', '167', '173']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '166', 'type': 'False', 'children': []}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'fail_type'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ECGM'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'DIMENSION'}, {'id': '173', 'type': 'return_statement', 'children': ['174']}; {'id': '174', 'type': 'expression_list', 'children': ['175', '176', '177']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'fail_type'}, {'id': '177', 'type': 'None', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'less_equal'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '198']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'subtract'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'c1'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'c2'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tol'}, {'id': '199', 'type': 'if_statement', 'children': ['200', '210']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '205'], 'value': '!='}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}, {'id': '205', 'type': 'subscript', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'c2'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'block', 'children': ['211', '215', '221']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '214', 'type': 'False', 'children': []}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'fail_type'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ECGM'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'COORDS'}, {'id': '221', 'type': 'return_statement', 'children': ['222']}; {'id': '222', 'type': 'expression_list', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'fail_type'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '241']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}, {'id': '231', 'type': 'argument_list', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'a1'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'str'"}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'list_comprehension', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'atom_num'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '254', 'type': 'for_in_clause', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '257', 'type': 'if_statement', 'children': ['258', '272']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '266', 'type': 'call', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'string', 'children': [], 'value': "'str'"}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'a2'}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'list_comprehension', 'children': ['282', '285']}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'atom_num'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '285', 'type': 'for_in_clause', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'a2'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'equal'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'a2'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '309']}, {'id': '299', 'type': 'comparison_operator', 'children': ['300', '304'], 'value': '!='}; {'id': '300', 'type': 'call', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}; {'id': '304', 'type': 'subscript', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '308', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '309', 'type': 'block', 'children': ['310', '314', '320']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '313', 'type': 'False', 'children': []}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'assignment', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'fail_type'}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'ECGM'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'ATOMS'}; {'id': '320', 'type': 'return_statement', 'children': ['321']}, {'id': '321', 'type': 'expression_list', 'children': ['322', '323', '324']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'fail_type'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'fail_loc'}, {'id': '325', 'type': 'return_statement', 'children': ['326']}; {'id': '326', 'type': 'expression_list', 'children': ['327', '328', '329']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '328', 'type': 'None', 'children': []}, {'id': '329', 'type': 'None', 'children': []} | def check_geom(c1, a1, c2, a2, tol=_DEF.XYZ_COORD_MATCH_TOL):
from ..const import atom_num
import numpy as np
from ..const import EnumCheckGeomMismatch as ECGM
match = True
if not len(c1.shape) == 1:
raise ValueError(("'c1' is not a vector."))
if not len(c2.shape) == 1:
raise ValueError(("'c2' is not a vector."))
if not len(a1.shape) == 1:
raise ValueError(("'a1' is not a simple list."))
if not len(a2.shape) == 1:
raise ValueError(("'a2' is not a simple list."))
if not c1.shape[0] == 3 * a1.shape[0]:
raise ValueError("len(c1) != 3*len(a1)")
if not c2.shape[0] == 3 * a2.shape[0]:
raise ValueError("len(c2) != 3*len(a2)")
if not c1.shape[0] == c2.shape[0]:
match = False
fail_type = ECGM.DIMENSION
return match, fail_type, None
fail_loc = np.less_equal(np.abs(np.subtract(c1,c2)), tol)
if sum(fail_loc) != c2.shape[0]:
match = False
fail_type = ECGM.COORDS
return match, fail_type, fail_loc
if np.issubdtype(a1.dtype, np.dtype('str')):
a1 = np.array([atom_num[e] for e in a1])
if np.issubdtype(a2.dtype, np.dtype('str')):
a2 = np.array([atom_num[e] for e in a2])
fail_loc = np.equal(a1, a2)
if sum(fail_loc) != a2.shape[0]:
match = False
fail_type = ECGM.ATOMS
return match, fail_type, fail_loc
return match, None, None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assert_npfloatarray'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'varname'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'errsrc'}; {'id': '10', 'type': 'block', 'children': ['11', '16', '53', '96']}, {'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': 'numpy'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '25']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'varname'}, {'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': 'var'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '25', 'type': 'else_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'try_statement', 'children': ['28', '37']}; {'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': 'var'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'varname'}, {'id': '37', 'type': 'except_clause', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'raise_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45', '52']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': '"Attribute \'{0}\' not defined in \'{1}\'"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'varname'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'errsrc'}, {'id': '53', 'type': 'try_statement', 'children': ['54', '61', '76']}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '61', 'type': 'except_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'raise_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '75']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': '"\'{0}\' is not an np.array (lacks a \'dtype\' member)"'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'errsrc'}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'if_statement', 'children': ['79', '83']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'raise_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89', '95']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': '"\'{0}\' is not an np.array (\'len(shape)\' < 1)"'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'errsrc'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '107']}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'raise_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113', '119']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"\'{0}\' is not an np.array of np.float"'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'errsrc'} | def assert_npfloatarray(obj, varname, desc, exc, tc, errsrc):
import numpy as np
if varname is None:
var = obj
else:
try:
var = getattr(obj, varname)
except AttributeError:
raise exc(tc, "Attribute '{0}' not defined in '{1}'"
.format(varname, obj), errsrc)
try:
dt = var.dtype
except AttributeError:
raise exc(tc, "'{0}' is not an np.array (lacks a 'dtype' member)"
.format(desc), errsrc)
else:
if not var.shape:
raise exc(tc, "'{0}' is not an np.array ('len(shape)' < 1)"
.format(desc), errsrc)
if not np.issubdtype(dt, np.float):
raise exc(tc, "'{0}' is not an np.array of np.float".format(desc),
errsrc) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_advance_pattern_generators'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '80']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'valid_generators'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '25', '67']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'range'}, {'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': 'max_trials'}, {'id': '25', 'type': 'block', 'children': ['26', '53', '60']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '44']}, {'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': 'alltrue'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'list_comprehension', 'children': ['33', '41']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '__distance_valid'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'valid_generators'}; {'id': '44', 'type': 'block', 'children': ['45', '52']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'valid_generators'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '52', 'type': 'break_statement', 'children': []}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'force_new_dynamic_value'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'force_new_dynamic_value'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '%'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"Unable to place pattern %s subject to given constraints"'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'valid_generators'} | def _advance_pattern_generators(self,p):
valid_generators = []
for g in p.generators:
for trial in range(self.max_trials):
if np.alltrue([self.__distance_valid(g,v,p) for v in valid_generators]):
valid_generators.append(g)
break
g.force_new_dynamic_value('x')
g.force_new_dynamic_value('y')
else:
self.warning("Unable to place pattern %s subject to given constraints" %
g.name)
return valid_generators |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'register'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'settings_class'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'NoSwitcher'}; {'id': '8', 'type': 'list_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'simple_checks'}; {'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '12', 'type': 'block', 'children': ['13', '38', '48', '68']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'settings_class'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'NoSwitcher'}, {'id': '17', 'type': 'block', 'children': ['18', '36']}; {'id': '18', 'type': 'function_definition', 'children': ['19', '20', '22']}, {'id': '19', 'type': 'function_name', 'children': [], 'value': 'decorator'}; {'id': '20', 'type': 'parameters', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '22', 'type': 'block', 'children': ['23', '34']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '32']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '30', 'type': 'list_splat', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'simple_checks'}; {'id': '32', 'type': 'dictionary_splat', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'decorator'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'available_checks'}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '55']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'conditions'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'not'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'condition'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'available_checks'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'raise_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'InvalidCondition'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'}; {'id': '66', 'type': 'string', 'children': [], 'value': '\'There is no check for the condition "%s"\''}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'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': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_registry'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'tuple', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'settings_class'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'simple_checks'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'conditions'} | def register(self, settings_class=NoSwitcher, *simple_checks,
**conditions):
if settings_class is NoSwitcher:
def decorator(cls):
self.register(cls, *simple_checks, **conditions)
return cls
return decorator
available_checks = self.checks.keys()
for condition in conditions.keys():
if condition not in available_checks:
raise InvalidCondition(
'There is no check for the condition "%s"' % condition)
self._registry.append((settings_class, simple_checks, conditions)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_load_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bohrs'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '16', '25', '32', '49', '65', '81', '102', '167', '185', '195', '201', '209', '223', '231', '249']}, {'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': 'numpy'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'import_from_statement', 'children': ['17', '21', '23']}, {'id': '17', 'type': 'relative_import', 'children': ['18', '19']}; {'id': '18', 'type': 'import_prefix', 'children': []}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'atom_num'}, {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '25', 'type': 'import_from_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'relative_import', 'children': ['27', '28']}, {'id': '27', 'type': 'import_prefix', 'children': []}; {'id': '28', 'type': 'dotted_name', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '30', 'type': 'dotted_name', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'XYZError'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '39']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'geoms'"}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'raise_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'XYZError'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '47', '48']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'XYZError'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'OVERWRITE'}, {'id': '47', 'type': 'string', 'children': [], 'value': '"Cannot overwrite contents of existing OpanXYZ"'}; {'id': '48', 'type': 'string', 'children': [], 'value': '""'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '59']}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '=='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'raise_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': '"Coordinates are not a vector"'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '75']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '74'], 'value': '=='}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'raise_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Atom symbols are not a simple list"'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '96']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '89'], 'value': '=='}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '*'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'raise_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'string', 'children': [], 'value': '"len(coords) != 3 * len(atom_syms)"'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '127']}, {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '106', 'type': 'generator_expression', 'children': ['107', '117']}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108'], 'value': '()'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '116'], 'value': 'in'}, {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'atom_num'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'raise_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"Invalid atoms specified: {0}"'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'list_comprehension', 'children': ['138', '143']}; {'id': '138', 'type': 'tuple', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '143', 'type': 'for_in_clause', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '145', 'type': 'generator_expression', 'children': ['146', '147', '164']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'for_in_clause', 'children': ['148', '151']}; {'id': '148', 'type': 'tuple_pattern', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '163']}, {'id': '157', 'type': 'lambda', 'children': ['158', '160']}; {'id': '158', 'type': 'lambda_parameters', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'in'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'atom_num'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}; {'id': '164', 'type': 'if_clause', 'children': ['165']}, {'id': '165', 'type': 'not_operator', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '179']}; {'id': '168', 'type': 'not_operator', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'isreal'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'raise_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'string', 'children': [], 'value': '"All coordinates must be real numeric"'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '190', 'type': 'subscript', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'num_geoms'}; {'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': 'in_str'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'LOAD_DATA_FLAG'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'descs'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'list', 'children': ['220'], 'value': '[self.LOAD_DATA_FLAG]'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'LOAD_DATA_FLAG'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'XYZ_path'}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'LOAD_DATA_FLAG'}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'atom_syms'}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'geoms'}; {'id': '254', 'type': 'list', 'children': ['255'], 'value': '[coords / (1.0 if bohrs else PHYS.ANG_PER_BOHR)]'}, {'id': '255', 'type': 'binary_operator', 'children': ['256', '257'], 'value': '/'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '257', 'type': 'parenthesized_expression', 'children': ['258'], 'value': '()'}; {'id': '258', 'type': 'conditional_expression', 'children': ['259', '260', '261'], 'value': 'if'}, {'id': '259', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'bohrs'}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'PHYS'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'ANG_PER_BOHR'} | def _load_data(self, atom_syms, coords, bohrs=True):
import numpy as np
from .const import atom_num, PHYS
from .error import XYZError
if 'geoms' in dir(self):
raise XYZError(XYZError.OVERWRITE,
"Cannot overwrite contents of existing OpanXYZ", "")
if not len(coords.shape) == 1:
raise ValueError("Coordinates are not a vector")
if not len(atom_syms.shape) == 1:
raise ValueError("Atom symbols are not a simple list")
if not coords.shape[0] == 3 * atom_syms.shape[0]:
raise ValueError("len(coords) != 3 * len(atom_syms)")
if not all( (atom_syms[i].upper() in atom_num)
for i in range(atom_syms.shape[0]) ):
raise ValueError("Invalid atoms specified: {0}".format(
[(j, atom_syms[j]) for j in
(i for (i, valid) in
enumerate(map(lambda k: k in atom_num, atom_syms))
if not valid
)
] ))
if not all(map(np.isreal, coords)):
raise ValueError("All coordinates must be real numeric")
self.num_atoms = atom_syms.shape[0]
self.num_geoms = 1
self.in_str = self.LOAD_DATA_FLAG
self.descs = np.array([self.LOAD_DATA_FLAG])
self.XYZ_path = self.LOAD_DATA_FLAG
self.atom_syms = list(map(str.upper, list(atom_syms)))
self.geoms = [coords / (1.0 if bohrs else PHYS.ANG_PER_BOHR)] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dist_single'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_num'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '8', 'type': 'block', 'children': ['9', '14', '21', '30', '53', '76', '91', '106', '139']}, {'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': 'numpy'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '17']}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '17', 'type': 'aliased_import', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '21', 'type': 'import_from_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'relative_import', 'children': ['23', '24']}, {'id': '23', 'type': 'import_prefix', 'children': []}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '26', 'type': 'aliased_import', 'children': ['27', '29']}, {'id': '27', 'type': 'dotted_name', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'safe_cast'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '42']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'parenthesized_expression', 'children': ['33'], 'value': '()'}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '38', '39'], 'value': '<='}; {'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'raise_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_1\' ({0})"'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '65']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'parenthesized_expression', 'children': ['56'], 'value': '()'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '61', '62'], 'value': '<='}, {'id': '57', 'type': 'unary_operator', 'children': ['58'], 'value': '-'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'raise_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_2\' ({0})"'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'scast'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '88']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'floor'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '103']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'int_'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110', '115']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '=='}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '114', 'type': 'float', 'children': [], 'value': '0.0'}, {'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', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '136']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'displ_single'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134', '135']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'g_num'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'float_'}, {'id': '139', 'type': 'return_statement', 'children': ['140']} | def dist_single(self, g_num, at_1, at_2):
import numpy as np
from scipy import linalg as spla
from .utils import safe_cast as scast
if not (-self.num_atoms <= at_1 < self.num_atoms):
raise IndexError("Invalid index for 'at_1' ({0})".format(at_1))
if not (-self.num_atoms <= at_2 < self.num_atoms):
raise IndexError("Invalid index for 'at_2' ({0})".format(at_2))
at_1 = scast(np.floor(at_1), np.int_)
at_2 = scast(np.floor(at_2), np.int_)
if at_1 == at_2:
dist = 0.0
else:
dist = scast(
spla.norm(self.displ_single(g_num, at_1, at_2)),
np.float_)
return dist |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dist_iter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'invalid_error'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '17', '24', '57', '68', '76', '84']}; {'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': 'numpy'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '17', 'type': 'import_from_statement', 'children': ['18', '22']}; {'id': '18', 'type': 'relative_import', 'children': ['19', '20']}, {'id': '19', 'type': 'import_prefix', 'children': []}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'id': '26', 'type': 'block', 'children': ['27', '37', '47']}, {'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': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'string', 'children': [], 'value': '"g_nums = {0}"'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'g_nums'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"ats_1 = {0}"'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'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': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"ats_2 = {0}"'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ats_2'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_none_subst'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'list_splat', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'yield', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_iter_return'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '99']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dist_single'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'invalid_error'} | def dist_iter(self, g_nums, ats_1, ats_2, invalid_error=False):
import numpy as np
from .utils import pack_tups
if _DEBUG:
print("g_nums = {0}".format(g_nums))
print("ats_1 = {0}".format(ats_1))
print("ats_2 = {0}".format(ats_2))
arglist = self._none_subst(g_nums, ats_1, ats_2)
tups = pack_tups(*arglist)
if _DEBUG:
print(tups)
for tup in tups:
yield self._iter_return(tup, self.dist_single, invalid_error) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'angle_single'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_num'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '9', 'type': 'block', 'children': ['10', '15', '24', '32', '55', '78', '101', '116', '131', '146', '166', '186', '203', '214', '225', '233']}; {'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': 'numpy'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'relative_import', 'children': ['17', '18']}, {'id': '17', 'type': 'import_prefix', 'children': []}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '20', 'type': 'aliased_import', 'children': ['21', '23']}, {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'safe_cast'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '24', 'type': 'import_from_statement', 'children': ['25', '30']}, {'id': '25', 'type': 'relative_import', 'children': ['26', '27']}; {'id': '26', 'type': 'import_prefix', 'children': []}, {'id': '27', 'type': 'dotted_name', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'vector'}; {'id': '30', 'type': 'dotted_name', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'vec_angle'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '44']}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'parenthesized_expression', 'children': ['35'], 'value': '()'}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '40', '41'], 'value': '<='}; {'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'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': 'IndexError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_1\' ({0})"'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '67']}; {'id': '56', 'type': 'not_operator', 'children': ['57']}, {'id': '57', 'type': 'parenthesized_expression', 'children': ['58'], 'value': '()'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '63', '64'], 'value': '<='}, {'id': '59', 'type': 'unary_operator', 'children': ['60'], 'value': '-'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'raise_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_2\' ({0})"'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '90']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81'], 'value': '()'}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '86', '87'], 'value': '<='}; {'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_3\' ({0})"'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '113']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'int_'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'scast'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '128']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'floor'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'at_3'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '143']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'int_'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '160']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '154'], 'value': '=='}; {'id': '148', 'type': 'parenthesized_expression', 'children': ['149'], 'value': '()'}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '154', 'type': 'parenthesized_expression', 'children': ['155'], 'value': '()'}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '%'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'raise_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': '"\'at_1\' and \'at_2\' must be different"'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '180']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '174'], 'value': '=='}; {'id': '168', 'type': 'parenthesized_expression', 'children': ['169'], 'value': '()'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '%'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '174', 'type': 'parenthesized_expression', 'children': ['175'], 'value': '()'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'string', 'children': [], 'value': '"\'at_2\' and \'at_3\' must be different"'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '200']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '194'], 'value': '=='}; {'id': '188', 'type': 'parenthesized_expression', 'children': ['189'], 'value': '()'}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '%'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '194', 'type': 'parenthesized_expression', 'children': ['195'], 'value': '()'}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'return_statement', 'children': ['202']}; {'id': '202', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'vec_2_1'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'displ_single'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212', '213']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'g_num'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'vec_2_3'}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'displ_single'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223', '224']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'g_num'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'at_3'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'angle'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'vec_angle'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'vec_2_1'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'vec_2_3'}, {'id': '233', 'type': 'return_statement', 'children': ['234']} | def angle_single(self, g_num, at_1, at_2, at_3):
import numpy as np
from .utils import safe_cast as scast
from .utils.vector import vec_angle
if not(-self.num_atoms <= at_1 < self.num_atoms):
raise IndexError("Invalid index for 'at_1' ({0})".format(at_1))
if not(-self.num_atoms <= at_2 < self.num_atoms):
raise IndexError("Invalid index for 'at_2' ({0})".format(at_2))
if not(-self.num_atoms <= at_3 < self.num_atoms):
raise IndexError("Invalid index for 'at_3' ({0})".format(at_3))
at_1 = scast(np.floor(at_1), np.int_)
at_2 = scast(np.floor(at_2), np.int_)
at_3 = scast(np.floor(at_3), np.int_)
if (at_2 % self.num_atoms) == (at_1 % self.num_atoms):
raise ValueError("'at_1' and 'at_2' must be different")
if (at_2 % self.num_atoms) == (at_3 % self.num_atoms):
raise ValueError("'at_2' and 'at_3' must be different")
if (at_1 % self.num_atoms) == (at_3 % self.num_atoms):
return 0.0
vec_2_1 = self.displ_single(g_num, at_2, at_1)
vec_2_3 = self.displ_single(g_num, at_2, at_3)
angle = vec_angle(vec_2_1, vec_2_3)
return angle |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'angle_iter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'invalid_error'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '20', '63', '75', '83', '91']}, {'id': '13', 'type': 'import_from_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'relative_import', 'children': ['15', '16']}, {'id': '15', 'type': 'import_prefix', 'children': []}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'id': '22', 'type': 'block', 'children': ['23', '33', '43', '53']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"g_nums = {0}"'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'g_nums'}, {'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': '"ats_1 = {0}"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': '"ats_2 = {0}"'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ats_2'}, {'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': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"ats_3 = {0}"'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_none_subst'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72', '73', '74']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'list_splat', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'arglist'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '94', 'type': 'block', 'children': ['95', '103']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'yield', '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': '_iter_return'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111', '114']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'angle_single'} | def angle_iter(self, g_nums, ats_1, ats_2, ats_3, invalid_error=False):
from .utils import pack_tups
if _DEBUG:
print("g_nums = {0}".format(g_nums))
print("ats_1 = {0}".format(ats_1))
print("ats_2 = {0}".format(ats_2))
print("ats_3 = {0}".format(ats_3))
arglist = self._none_subst(g_nums, ats_1, ats_2, ats_3)
tups = pack_tups(*arglist)
if _DEBUG:
print(tups)
for tup in tups:
if _DEBUG:
print(tup)
yield self._iter_return(tup, self.angle_single, invalid_error) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dihed_iter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ats_4'}; {'id': '10', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'invalid_error'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '22', '75', '88', '96', '104']}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'relative_import', 'children': ['17', '18']}, {'id': '17', 'type': 'import_prefix', 'children': []}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'id': '24', 'type': 'block', 'children': ['25', '35', '45', '55', '65']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"g_nums = {0}"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'g_nums'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': '"ats_1 = {0}"'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'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': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"ats_2 = {0}"'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ats_2'}, {'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': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"ats_3 = {0}"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'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': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': '"ats_4 = {0}"'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ats_4'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'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': '_none_subst'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85', '86', '87']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ats_3'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ats_4'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'list_splat', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}; {'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': 'identifier', 'children': [], 'value': 'tups'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '107']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'yield', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': '_iter_return'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116', '119']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dihed_single'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'invalid_error'} | def dihed_iter(self, g_nums, ats_1, ats_2, ats_3, ats_4, \
invalid_error=False):
from .utils import pack_tups
if _DEBUG:
print("g_nums = {0}".format(g_nums))
print("ats_1 = {0}".format(ats_1))
print("ats_2 = {0}".format(ats_2))
print("ats_3 = {0}".format(ats_3))
print("ats_4 = {0}".format(ats_4))
arglist = self._none_subst(g_nums, ats_1, ats_2, ats_3, ats_4)
tups = pack_tups(*arglist)
if _DEBUG:
print(tups)
for tup in tups:
yield self._iter_return(tup, self.dihed_single, invalid_error) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'displ_single'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_num'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '8', 'type': 'block', 'children': ['9', '14', '23', '46', '69', '84', '99', '124', '133', '163']}, {'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': 'numpy'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '19']}, {'id': '15', 'type': 'relative_import', 'children': ['16', '17']}; {'id': '16', 'type': 'import_prefix', 'children': []}, {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '19', 'type': 'aliased_import', 'children': ['20', '22']}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'safe_cast'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'scast'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '35']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'parenthesized_expression', 'children': ['26'], 'value': '()'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '31', '32'], 'value': '<='}, {'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_1\' ({0})"'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '58']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'parenthesized_expression', 'children': ['49'], 'value': '()'}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '54', '55'], 'value': '<='}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'raise_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"Invalid index for \'at_2\' ({0})"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'scast'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '81']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'int_'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'at_2'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'scast'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '96']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'floor'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '113']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '107'], 'value': '=='}, {'id': '101', 'type': 'parenthesized_expression', 'children': ['102'], 'value': '()'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'at_1'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108'], 'value': '()'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'list', 'children': ['121', '122', '123'], 'value': '[0.0, 0.0, 0.0]'}, {'id': '121', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '122', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '123', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'geom_single'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'g_num'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'displ'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'list_comprehension', 'children': ['142', '157']}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '150'], 'value': '-'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '*'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'at_2'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '+'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '*'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'at_1'}, {'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '163', 'type': 'return_statement', 'children': ['164']} | def displ_single(self, g_num, at_1, at_2):
import numpy as np
from .utils import safe_cast as scast
if not (-self.num_atoms <= at_1 < self.num_atoms):
raise IndexError("Invalid index for 'at_1' ({0})".format(at_1))
if not (-self.num_atoms <= at_2 < self.num_atoms):
raise IndexError("Invalid index for 'at_2' ({0})".format(at_2))
at_1 = scast(np.floor(at_1), np.int_)
at_2 = scast(np.floor(at_2), np.int_)
if (at_1 % self.num_atoms) == (at_2 % self.num_atoms):
return np.array([0.0, 0.0, 0.0])
g = self.geom_single(g_num)
displ = np.array([ g[i + 3*at_2] - g[i + 3*at_1] for i in range(3) ])
return displ |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'displ_iter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ats_1'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'invalid_error'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '52', '63', '71', '79']}; {'id': '12', 'type': 'import_from_statement', 'children': ['13', '17']}, {'id': '13', 'type': 'relative_import', 'children': ['14', '15']}; {'id': '14', 'type': 'import_prefix', 'children': []}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}, {'id': '21', 'type': 'block', 'children': ['22', '32', '42']}; {'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': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"g_nums = {0}"'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'g_nums'}; {'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': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"ats_1 = {0}"'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ats_1'}; {'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': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"ats_2 = {0}"'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ats_2'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'arglist'}, {'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': '_none_subst'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'g_nums'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ats_1'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ats_2'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pack_tups'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'list_splat', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'arglist'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': '_DEBUG'}, {'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': 'print'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tups'}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'tups'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'yield', 'children': ['85']}, {'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': '_iter_return'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91', '94']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'displ_single'} | def displ_iter(self, g_nums, ats_1, ats_2, invalid_error=False):
from .utils import pack_tups
if _DEBUG:
print("g_nums = {0}".format(g_nums))
print("ats_1 = {0}".format(ats_1))
print("ats_2 = {0}".format(ats_2))
arglist = self._none_subst(g_nums, ats_1, ats_2)
tups = pack_tups(*arglist)
if _DEBUG:
print(tups)
for tup in tups:
yield self._iter_return(tup, self.displ_single, invalid_error) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_none_subst'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'block', 'children': ['8', '13', '21', '25', '46', '163']}; {'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': 'numpy'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'none_found'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'none_vals'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '45']}; {'id': '34', 'type': 'lambda', 'children': ['35', '37']}, {'id': '35', 'type': 'lambda_parameters', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'e'}, {'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': 'e'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '55', '76']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '54'], 'value': '>'}; {'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': 'count_nonzero'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'none_vals'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'ValueError'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Multiple \'None\' values [indices {0}] not supported"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'subscript', 'children': ['69', '75']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'nonzero'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'none_vals'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '85']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '84'], 'value': '=='}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'count_nonzero'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'none_vals'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'block', 'children': ['86', '127', '131', '144']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '121']}, {'id': '87', 'type': 'not_operator', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'equal'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '106']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '120']}; {'id': '112', 'type': 'lambda', 'children': ['113', '115']}, {'id': '113', 'type': 'lambda_parameters', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'arglist'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'raise_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'string', 'children': [], 'value': '"\'None\' as parameter invalid with non-str iterables"'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'none_found'}; {'id': '130', 'type': 'True', 'children': []}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'none_loc'}; {'id': '134', 'type': 'subscript', 'children': ['135', '143']}, {'id': '135', 'type': 'subscript', 'children': ['136', '142']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'nonzero'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'none_vals'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '149', '150']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'arglist'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'none_loc'}, {'id': '149', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'conditional_expression', 'children': ['154', '157', '160'], 'value': 'if'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'num_geoms'}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '=='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'none_loc'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'num_atoms'}, {'id': '163', 'type': 'return_statement', 'children': ['164']} | def _none_subst(self, *args):
import numpy as np
arglist = [a for a in args]
none_found = False
none_vals = list(map(lambda e: isinstance(e, type(None)), arglist))
if np.count_nonzero(none_vals) > 1:
raise ValueError(
"Multiple 'None' values [indices {0}] not supported"
.format(tuple(np.nonzero(none_vals)[0])))
elif np.count_nonzero(none_vals) == 1:
if not all(np.equal(list(map(np.iterable, arglist)),
list(map(lambda e: isinstance(e, str), arglist)))):
raise ValueError(
"'None' as parameter invalid with non-str iterables")
none_found = True
none_loc = np.nonzero(none_vals)[0][0]
arglist[none_loc] = \
range(self.num_geoms if none_loc == 0 else self.num_atoms)
return arglist |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'new_from_files'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '13', '18', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'basepath'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '8', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'bohrs'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'software'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_E_SW'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ORCA'}; {'id': '18', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'repo_clobber'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'dictionary_splat_pattern', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '24', 'type': 'block', 'children': ['25', '28', '35', '44', '53', '62', '71', '84', '93', '100', '109', '126', '143', '160', '177', '199', '227', '255', '270', '300', '315', '342']}, {'id': '25', 'type': 'import_statement', 'children': ['26']}; {'id': '26', 'type': 'dotted_name', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '28', 'type': 'import_from_statement', 'children': ['29', '31']}, {'id': '29', 'type': 'dotted_name', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '31', 'type': 'aliased_import', 'children': ['32', '34']}; {'id': '32', 'type': 'dotted_name', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'osp'}, {'id': '35', 'type': 'import_from_statement', 'children': ['36', '40']}; {'id': '36', 'type': 'relative_import', 'children': ['37', '38']}, {'id': '37', 'type': 'import_prefix', 'children': []}; {'id': '38', 'type': 'dotted_name', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'xyz'}; {'id': '40', 'type': 'aliased_import', 'children': ['41', '43']}, {'id': '41', 'type': 'dotted_name', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'OpanXYZ'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'OX'}; {'id': '44', 'type': 'import_from_statement', 'children': ['45', '49']}, {'id': '45', 'type': 'relative_import', 'children': ['46', '47']}; {'id': '46', 'type': 'import_prefix', 'children': []}, {'id': '47', 'type': 'dotted_name', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'grad'}, {'id': '49', 'type': 'aliased_import', 'children': ['50', '52']}; {'id': '50', 'type': 'dotted_name', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'OrcaEngrad'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'OE'}, {'id': '53', 'type': 'import_from_statement', 'children': ['54', '58']}; {'id': '54', 'type': 'relative_import', 'children': ['55', '56']}, {'id': '55', 'type': 'import_prefix', 'children': []}; {'id': '56', 'type': 'dotted_name', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'hess'}; {'id': '58', 'type': 'aliased_import', 'children': ['59', '61']}, {'id': '59', 'type': 'dotted_name', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'OrcaHess'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'OH'}; {'id': '62', 'type': 'import_from_statement', 'children': ['63', '67']}, {'id': '63', 'type': 'relative_import', 'children': ['64', '65']}; {'id': '64', 'type': 'import_prefix', 'children': []}, {'id': '65', 'type': 'dotted_name', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '67', 'type': 'aliased_import', 'children': ['68', '70']}; {'id': '68', 'type': 'dotted_name', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'OpanAnharmRepo'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'OR'}, {'id': '71', 'type': 'import_from_statement', 'children': ['72', '76', '80']}; {'id': '72', 'type': 'relative_import', 'children': ['73', '74']}, {'id': '73', 'type': 'import_prefix', 'children': []}; {'id': '74', 'type': 'dotted_name', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '76', 'type': 'aliased_import', 'children': ['77', '79']}, {'id': '77', 'type': 'dotted_name', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'EnumDispDirection'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'E_DDir'}; {'id': '80', 'type': 'aliased_import', 'children': ['81', '83']}, {'id': '81', 'type': 'dotted_name', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'EnumFileType'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'E_FT'}; {'id': '84', 'type': 'import_from_statement', 'children': ['85', '89']}, {'id': '85', 'type': 'relative_import', 'children': ['86', '87']}; {'id': '86', 'type': 'import_prefix', 'children': []}, {'id': '87', 'type': 'dotted_name', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '89', 'type': 'aliased_import', 'children': ['90', '92']}; {'id': '90', 'type': 'dotted_name', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'EnumSoftware'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'E_SW'}, {'id': '93', 'type': 'import_from_statement', 'children': ['94', '98']}; {'id': '94', 'type': 'relative_import', 'children': ['95', '96']}, {'id': '95', 'type': 'import_prefix', 'children': []}; {'id': '96', 'type': 'dotted_name', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '98', 'type': 'dotted_name', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'DEF'}; {'id': '100', 'type': 'import_from_statement', 'children': ['101', '105']}, {'id': '101', 'type': 'relative_import', 'children': ['102', '103']}; {'id': '102', 'type': 'import_prefix', 'children': []}, {'id': '103', 'type': 'dotted_name', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '105', 'type': 'aliased_import', 'children': ['106', '108']}; {'id': '106', 'type': 'dotted_name', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'AnharmError'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '116']}; {'id': '110', 'type': 'not_operator', 'children': ['111']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '=='}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'w_xyz'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'raise_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '124', '125']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'STATUS'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"XYZ object is already bound"'}, {'id': '125', 'type': 'string', 'children': [], 'value': '""'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '133']}, {'id': '127', 'type': 'not_operator', 'children': ['128']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': '=='}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'w_grad'}; {'id': '132', 'type': 'None', 'children': []}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'raise_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '141', '142']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'STATUS'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"GRAD object is already bound"'}; {'id': '142', 'type': 'string', 'children': [], 'value': '""'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '150']}; {'id': '144', 'type': 'not_operator', 'children': ['145']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '=='}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'w_hess'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'raise_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '158', '159']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'STATUS'}; {'id': '158', 'type': 'string', 'children': [], 'value': '"HESS object is already bound"'}, {'id': '159', 'type': 'string', 'children': [], 'value': '""'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '167']}, {'id': '161', 'type': 'not_operator', 'children': ['162']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '166'], 'value': '=='}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'raise_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '175', '176']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ANHErr'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'STATUS'}, {'id': '175', 'type': 'string', 'children': [], 'value': '"Repository object is already bound"'}; {'id': '176', 'type': 'string', 'children': [], 'value': '""'}, {'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': 'w_xyz'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'OX'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '189', 'type': 'argument_list', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'basepath'}, {'id': '191', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '198'], 'value': '+'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'osp'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'extsep'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'xyz_ext'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'w_grad'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'OE'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '221', '222', '223', '226']}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'basepath'}, {'id': '213', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '220'], 'value': '+'}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'osp'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'extsep'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'engrad_ext'}, {'id': '221', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'E_DDir'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'NO_DISP'}; {'id': '226', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'w_hess'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'OH'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '249', '250', '251', '254']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'basepath'}, {'id': '241', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '248'], 'value': '+'}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'osp'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'extsep'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'hess_ext'}, {'id': '249', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'E_DDir'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'NO_DISP'}; {'id': '254', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '262']}; {'id': '256', 'type': 'not_operator', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'raise_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '+'}; {'id': '268', 'type': 'string', 'children': [], 'value': '"Must create new repository when loading "'}, {'id': '269', 'type': 'string', 'children': [], 'value': '"a new dataset."'}; {'id': '270', 'type': 'if_statement', 'children': ['271', '289']}, {'id': '271', 'type': 'boolean_operator', 'children': ['272', '282'], 'value': 'and'}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '281'], 'value': '>'}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '280', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '281', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '282', 'type': 'not_operator', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'isabs'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'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': 'repo'}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'basepath'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '300', 'type': 'if_statement', 'children': ['301', '307']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'raise_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'binary_operator', 'children': ['313', '314'], 'value': '+'}, {'id': '313', 'type': 'string', 'children': [], 'value': '"Cannot bind repository -- specified "'}; {'id': '314', 'type': 'string', 'children': [], 'value': '"location is a directory"'}, {'id': '315', 'type': 'if_statement', 'children': ['316', '322']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'osp'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '322', 'type': 'block', 'children': ['323']}, {'id': '323', 'type': 'if_statement', 'children': ['324', '325', '333']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'repo_clobber'}, {'id': '325', 'type': 'block', 'children': ['326']}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '333', 'type': 'else_clause', 'children': ['334']}; {'id': '334', 'type': 'block', 'children': ['335']}, {'id': '335', 'type': 'raise_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'binary_operator', 'children': ['340', '341'], 'value': '+'}; {'id': '340', 'type': 'string', 'children': [], 'value': '"Target repository file exists and "'}, {'id': '341', 'type': 'string', 'children': [], 'value': '"clobber is disabled."'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'assignment', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '347', 'type': 'call', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'OR'}, {'id': '349', 'type': 'argument_list', 'children': ['350']} | def new_from_files(self, basepath, basename, repo, \
bohrs=False, \
software=_E_SW.ORCA, \
repo_clobber=False, **kwargs):
import os
from os import path as osp
from ..xyz import OpanXYZ as OX
from ..grad import OrcaEngrad as OE
from ..hess import OrcaHess as OH
from .repo import OpanAnharmRepo as OR
from ..const import EnumDispDirection as E_DDir, EnumFileType as E_FT
from ..const import EnumSoftware as E_SW
from ..const import DEF
from ..error import AnharmError as ANHErr
if not self.w_xyz == None:
raise ANHErr(ANHErr.STATUS,
"XYZ object is already bound",
"")
if not self.w_grad == None:
raise ANHErr(ANHErr.STATUS,
"GRAD object is already bound",
"")
if not self.w_hess == None:
raise ANHErr(ANHErr.STATUS,
"HESS object is already bound",
"")
if not self.repo == None:
raise ANHErr(ANHErr.STATUS,
"Repository object is already bound",
"")
self.w_xyz = OX( osp.join(basepath, \
basename + osp.extsep + xyz_ext) )
self.w_grad = OE( osp.join(basepath, \
basename + osp.extsep + engrad_ext), \
0, E_DDir.NO_DISP, 0.0 )
self.w_hess = OH( osp.join(basepath, \
basename + osp.extsep + hess_ext), \
0, E_DDir.NO_DISP, 0.0 )
if not isinstance(repo, str):
raise TypeError("Must create new repository when loading " +
"a new dataset.")
if osp.split(repo[0]) > 0 and not osp.isabs(repo):
repo = osp.join(basepath, repo)
if osp.isdir(repo):
raise IOError("Cannot bind repository -- specified " +
"location is a directory")
if osp.isfile(repo):
if repo_clobber:
os.remove(repo)
else:
raise IOError("Target repository file exists and " +
"clobber is disabled.")
self.repo = OR(repo) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_locus_read'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'locus_read'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'n_ref'}, {'id': '7', 'type': 'block', 'children': ['8', '14', '20', '26', '32', '38', '53', '59', '74', '155', '166', '176', '184', '194', '204']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'reference_positions'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'reference_positions'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'read_pos_before'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'base0_read_position_before_variant'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'read_pos_after'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'base0_read_position_after_variant'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reference_positions'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'read_pos_before'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '51']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': '"Missing reference pos for nucleotide before variant on read: %s"'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'reference_positions'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'read_pos_after'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'block', 'children': ['64', '72']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"Missing reference pos for nucleotide after variant on read: %s"'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'locus_read'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78', '129']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '=='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'n_ref'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'block', 'children': ['79', '98', '109']}, {'id': '79', 'type': 'if_statement', 'children': ['80', '85']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '84'], 'value': '!='}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '-'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'block', 'children': ['86', '96']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94', '95']}; {'id': '92', 'type': 'string', 'children': [], 'value': '"Positions before (%d) and after (%d) variant should be adjacent on read %s"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'locus_read'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ref_positions_for_inserted'}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'reference_positions'}, {'id': '103', 'type': 'slice', 'children': ['104', '107', '108']}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'read_pos_before'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '107', 'type': 'colon', 'children': []}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'read_pos_after'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '119']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '112', 'type': 'generator_expression', 'children': ['113', '116']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'insert_pos'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'insert_pos'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ref_positions_for_inserted'}, {'id': '119', 'type': 'block', 'children': ['120', '127']}; {'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': 'logger'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'string', 'children': [], 'value': '"Skipping read, inserted nucleotides shouldn\'t map to reference"'}, {'id': '127', 'type': 'return_statement', 'children': ['128']}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'else_clause', 'children': ['130']}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'if_statement', 'children': ['132', '139']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '!='}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '-'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '+'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'n_ref'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'block', 'children': ['140', '153']}; {'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': 'logger'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '150', '151', '152']}; {'id': '146', 'type': 'parenthesized_expression', 'children': ['147'], 'value': '()'}, {'id': '147', 'type': 'concatenated_string', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"Positions before (%d) and after (%d) variant should be "'}, {'id': '149', 'type': 'string', 'children': [], 'value': '"adjacent on read %s"'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ref_pos_before'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ref_pos_after'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'None', 'children': []}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'nucleotides_at_variant_locus'}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '160', 'type': 'slice', 'children': ['161', '164', '165']}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'read_pos_before'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'colon', 'children': []}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'read_pos_after'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '171', 'type': 'slice', 'children': ['172', '173']}; {'id': '172', 'type': 'colon', 'children': []}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '+'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'read_pos_before'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '181', 'type': 'slice', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'read_pos_after'}, {'id': '183', 'type': 'colon', 'children': []}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '189']}; {'id': '186', 'type': 'pattern_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'convert_from_bytes_if_necessary'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '199']}; {'id': '196', 'type': 'pattern_list', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'trim_N_nucleotides'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '204', 'type': 'return_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210', '211']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'nucleotides_at_variant_locus'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'locus_read'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'} | def from_locus_read(cls, locus_read, n_ref):
sequence = locus_read.sequence
reference_positions = locus_read.reference_positions
read_pos_before = locus_read.base0_read_position_before_variant
read_pos_after = locus_read.base0_read_position_after_variant
ref_pos_before = reference_positions[read_pos_before]
if ref_pos_before is None:
logger.warn(
"Missing reference pos for nucleotide before variant on read: %s",
locus_read)
return None
ref_pos_after = reference_positions[read_pos_after]
if ref_pos_after is None:
logger.warn(
"Missing reference pos for nucleotide after variant on read: %s",
locus_read)
return None
if n_ref == 0:
if ref_pos_after - ref_pos_before != 1:
logger.debug(
"Positions before (%d) and after (%d) variant should be adjacent on read %s",
ref_pos_before,
ref_pos_after,
locus_read)
return None
ref_positions_for_inserted = reference_positions[
read_pos_before + 1:read_pos_after]
if any(insert_pos is not None for insert_pos in ref_positions_for_inserted):
logger.debug(
"Skipping read, inserted nucleotides shouldn't map to reference")
return None
else:
if ref_pos_after - ref_pos_before != n_ref + 1:
logger.debug(
("Positions before (%d) and after (%d) variant should be "
"adjacent on read %s"),
ref_pos_before,
ref_pos_after,
locus_read)
return None
nucleotides_at_variant_locus = sequence[read_pos_before + 1:read_pos_after]
prefix = sequence[:read_pos_before + 1]
suffix = sequence[read_pos_after:]
prefix, suffix = convert_from_bytes_if_necessary(prefix, suffix)
prefix, suffix = trim_N_nucleotides(prefix, suffix)
return cls(
prefix,
nucleotides_at_variant_locus,
suffix,
name=locus_read.name) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mtx_refl'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nv'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reps'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'block', 'children': ['9', '14', '21', '28', '45', '63', '77', '95', '106', '124', '182', '199']}, {'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': 'numpy'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '17']}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '17', 'type': 'aliased_import', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '21', 'type': 'import_from_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'relative_import', 'children': ['23', '24']}, {'id': '23', 'type': 'import_prefix', 'children': []}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'const'}; {'id': '26', 'type': 'dotted_name', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '39']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '36'], 'value': '<'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'PRM'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'raise_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': '"Norm of \'nv\' is too small."'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'make_nd_vec'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55', '60']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'nd'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '62', 'type': 'True', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '71']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isscalar'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'reps'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'raise_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"\'reps\' must be scalar."'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '89']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '88']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'reps'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'raise_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"\'reps\' must be an integer."'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '100']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '>'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'reps'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'string', 'children': [], 'value': '"\'reps\' must be a positive integer."'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '119']}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '116', 'type': 'tuple', 'children': ['117', '118']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '130']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '138']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'if_statement', 'children': ['140', '143', '159']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '150']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148', '149']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '-'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '*'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '**'}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'nv'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '159', 'type': 'else_clause', 'children': ['160']}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '167']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '167', 'type': 'assignment', 'children': ['168', '172']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170', '171']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '179'], 'value': '*'}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '176'], 'value': '*'}; {'id': '174', 'type': 'unary_operator', 'children': ['175'], 'value': '-'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'nv'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'nv'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'refl_mtx'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'block_diag'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'list_splat', 'children': ['191']}, {'id': '191', 'type': 'list_comprehension', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}, {'id': '193', 'type': 'for_in_clause', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'reps'}, {'id': '199', 'type': 'return_statement', 'children': ['200']} | def mtx_refl(nv, reps=1):
import numpy as np
from scipy import linalg as spla
from ..const import PRM
if spla.norm(nv) < PRM.ZERO_VEC_TOL:
raise ValueError("Norm of 'nv' is too small.")
nv = make_nd_vec(nv, nd=3, t=np.float64, norm=True)
if not np.isscalar(reps):
raise ValueError("'reps' must be scalar.")
if not np.issubdtype(type(reps), int):
raise ValueError("'reps' must be an integer.")
if not reps > 0:
raise ValueError("'reps' must be a positive integer.")
base_mtx = np.zeros(shape=(3,3), dtype=np.float64)
for i in range(3):
for j in range(i,3):
if i==j:
base_mtx[i,j] = 1 - 2*nv[i]**2
else:
base_mtx[i,j] = base_mtx[j,i] = -2*nv[i]*nv[j]
refl_mtx= spla.block_diag(*[base_mtx for i in range(reps)])
return refl_mtx |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mtx_rot'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reps'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'block', 'children': ['10', '15', '22', '29', '46', '64', '78', '96', '107', '121', '162', '186', '231', '248']}; {'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': 'numpy'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '18']}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '18', 'type': 'aliased_import', 'children': ['19', '21']}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'spla'}; {'id': '22', 'type': 'import_from_statement', 'children': ['23', '27']}, {'id': '23', 'type': 'relative_import', 'children': ['24', '25']}; {'id': '24', 'type': 'import_prefix', 'children': []}, {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'const'}, {'id': '27', 'type': 'dotted_name', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '40']}; {'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': 'spla'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'PRM'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ZERO_VEC_TOL'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"Norm of \'ax\' is too small."'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'make_nd_vec'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53', '56', '61']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'nd'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'float64'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '63', 'type': 'True', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '72']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isscalar'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reps'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'raise_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"\'reps\' must be scalar."'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '90']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'issubdtype'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '89']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'reps'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"\'reps\' must be an integer."'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '101']}, {'id': '97', 'type': 'not_operator', 'children': ['98']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '>'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'reps'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"\'reps\' must be a positive integer."'}, {'id': '107', 'type': 'if_statement', 'children': ['108', '115']}; {'id': '108', 'type': 'not_operator', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isscalar'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'theta'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"\'theta\' must be scalar."'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'mod_lc'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '157']}, {'id': '129', 'type': 'list', 'children': ['130', '139', '148'], 'value': '[ [0, -ax[2], ax[1]],\n [ax[2], 0, -ax[0]],\n [-ax[1], ax[0], 0] ]'}; {'id': '130', 'type': 'list', 'children': ['131', '132', '136'], 'value': '[0, -ax[2], ax[1]]'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'unary_operator', 'children': ['133'], 'value': '-'}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'list', 'children': ['140', '143', '144'], 'value': '[ax[2], 0, -ax[0]]'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'unary_operator', 'children': ['145'], 'value': '-'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'list', 'children': ['149', '153', '156'], 'value': '[-ax[1], ax[0], 0]'}, {'id': '149', 'type': 'unary_operator', 'children': ['150'], 'value': '-'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ax_oprod'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '178']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'tuple', 'children': ['176', '177']}; {'id': '176', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'tuple', 'children': ['184', '185']}; {'id': '184', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '193', 'type': 'argument_list', 'children': ['194', '223']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '210']}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '209'], 'value': '*'}; {'id': '200', 'type': 'parenthesized_expression', 'children': ['201'], 'value': '()'}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '-'}; {'id': '202', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'cos'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'theta'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ax_oprod'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '217'], 'value': '*'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'cos'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'theta'}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'eye'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '223', 'type': 'binary_operator', 'children': ['224', '230'], 'value': '*'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'sin'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'mod_lc'}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rot_mtx'}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'spla'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'block_diag'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'list_splat', 'children': ['240']}; {'id': '240', 'type': 'list_comprehension', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'base_mtx'}; {'id': '242', 'type': 'for_in_clause', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'reps'}; {'id': '248', 'type': 'return_statement', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'rot_mtx'} | def mtx_rot(ax, theta, reps=1):
import numpy as np
from scipy import linalg as spla
from ..const import PRM
if spla.norm(ax) < PRM.ZERO_VEC_TOL:
raise ValueError("Norm of 'ax' is too small.")
ax = make_nd_vec(ax, nd=3, t=np.float64, norm=True)
if not np.isscalar(reps):
raise ValueError("'reps' must be scalar.")
if not np.issubdtype(type(reps), int):
raise ValueError("'reps' must be an integer.")
if not reps > 0:
raise ValueError("'reps' must be a positive integer.")
if not np.isscalar(theta):
raise ValueError("'theta' must be scalar.")
mod_lc = np.array([ [0, -ax[2], ax[1]],
[ax[2], 0, -ax[0]],
[-ax[1], ax[0], 0] ], dtype=np.float64)
ax_oprod = np.dot(ax.reshape((3,1)), ax.reshape((1,3)))
base_mtx = np.add(
np.add( (1.0 - np.cos(theta)) * ax_oprod,
np.cos(theta) * np.eye(3)
),
np.sin(theta) * mod_lc
)
rot_mtx= spla.block_diag(*[base_mtx for i in range(reps)])
return rot_mtx |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ffd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '22', '40', '53']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'weight'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '20', 'type': 'dictionary_splat', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sizes'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '37']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sizes'}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '52']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sizes'}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ff'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'} | def ffd(items, targets, **kwargs):
sizes = zip(items, weight(items, **kwargs))
sizes = sorted(sizes, key=operator.itemgetter(1), reverse=True)
items = map(operator.itemgetter(0), sizes)
return ff(items, targets) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_variant_sequence_to_reference_context'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'reference_context'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_transcript_mismatches'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'include_mismatches_after_variant'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_trimming_attempts'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '14', 'type': 'block', 'children': ['15', '19', '197']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '27']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '+'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_trimming_attempts'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '27', 'type': 'block', 'children': ['28', '63', '80', '95', '102', '109', '116', '131', '135', '142', '149', '168', '176', '186']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_too_short'}, {'id': '31', 'type': 'parenthesized_expression', 'children': ['32'], 'value': '()'}; {'id': '32', 'type': 'boolean_operator', 'children': ['33', '48'], 'value': 'or'}, {'id': '33', 'type': 'parenthesized_expression', 'children': ['34'], 'value': '()'}; {'id': '34', 'type': 'boolean_operator', 'children': ['35', '40'], 'value': 'and'}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'reference_context'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'strand'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"+"'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '47'], 'value': '<'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}; {'id': '48', 'type': 'parenthesized_expression', 'children': ['49'], 'value': '()'}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '55'], 'value': 'and'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '=='}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'reference_context'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '62'], 'value': '<'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_too_short'}, {'id': '65', 'type': 'block', 'children': ['66', '78']}; {'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': 'logger'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73', '74', '75']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"Variant sequence %s shorter than min allowed %d (iter=%d)"'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'None', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}, {'id': '83', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'VariantSequenceInReadingFrame'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'from_variant_sequence_and_reference_context'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '92']}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'reference_context'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'reference_context'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}; {'id': '98', 'type': 'None', 'children': []}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'n_mismatch_before_variant'}, {'id': '105', 'type': 'parenthesized_expression', 'children': ['106'], 'value': '()'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'number_mismatches_before_variant'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'n_mismatch_after_variant'}; {'id': '112', 'type': 'parenthesized_expression', 'children': ['113'], 'value': '()'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'number_mismatches_after_variant'}; {'id': '116', 'type': 'ERROR', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '124', '127', '130']}; {'id': '122', 'type': 'ERROR', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'Iter'}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'max_trimming_attempts'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'total_mismatches'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'n_mismatch_before_variant'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'include_mismatches_after_variant'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'total_mismatches'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'n_mismatch_after_variant'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '146']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '<='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'total_mismatches'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'max_transcript_mismatches'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'return_statement', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_in_reading_frame'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '159', '160', '161', '162', '165']}, {'id': '155', 'type': 'parenthesized_expression', 'children': ['156'], 'value': '()'}; {'id': '156', 'type': 'concatenated_string', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': '"Too many mismatches (%d) between variant sequence %s and "'}; {'id': '158', 'type': 'string', 'children': [], 'value': '"reference context %s (attempt=%d/%d)"'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'n_mismatch_before_variant'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'reference_context'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '+'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'max_trimming_attempts'}, {'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': 'current_min_coverage'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'min_coverage'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': '"Trimming to subsequence covered by at least %d reads"'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'current_min_coverage'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'variant_sequence'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'trim_by_coverage'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'current_min_coverage'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'return_statement', 'children': ['198']} | def match_variant_sequence_to_reference_context(
variant_sequence,
reference_context,
min_transcript_prefix_length,
max_transcript_mismatches,
include_mismatches_after_variant=False,
max_trimming_attempts=2):
variant_sequence_in_reading_frame = None
for i in range(max_trimming_attempts + 1):
variant_sequence_too_short = (
(reference_context.strand == "+" and
len(variant_sequence.prefix) < min_transcript_prefix_length) or
(reference_context.strand == "-" and
len(variant_sequence.suffix) < min_transcript_prefix_length)
)
if variant_sequence_too_short:
logger.info(
"Variant sequence %s shorter than min allowed %d (iter=%d)",
variant_sequence,
min_transcript_prefix_length,
i + 1)
return None
variant_sequence_in_reading_frame = \
VariantSequenceInReadingFrame.from_variant_sequence_and_reference_context(
variant_sequence=variant_sequence,
reference_context=reference_context)
if variant_sequence_in_reading_frame is None:
return None
n_mismatch_before_variant = (
variant_sequence_in_reading_frame.number_mismatches_before_variant)
n_mismatch_after_variant = (
variant_sequence_in_reading_frame.number_mismatches_after_variant)
logger.info("Iter
i + 1,
max_trimming_attempts + 1,
variant_sequence_in_reading_frame))
total_mismatches = n_mismatch_before_variant
if include_mismatches_after_variant:
total_mismatches += n_mismatch_after_variant
if total_mismatches <= max_transcript_mismatches:
return variant_sequence_in_reading_frame
logger.info(
("Too many mismatches (%d) between variant sequence %s and "
"reference context %s (attempt=%d/%d)"),
n_mismatch_before_variant,
variant_sequence,
reference_context,
i + 1,
max_trimming_attempts + 1)
current_min_coverage = variant_sequence.min_coverage()
logger.info(
"Trimming to subsequence covered by at least %d reads",
current_min_coverage + 1)
variant_sequence = variant_sequence.trim_by_coverage(
current_min_coverage + 1)
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'predicted_effects_for_variant'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'only_coding_changes'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '16', '79', '86', '93', '104']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'effects'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'transcripts'}, {'id': '21', 'type': 'block', 'children': ['22', '42', '67']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '29']}, {'id': '23', 'type': 'boolean_operator', 'children': ['24', '25'], 'value': 'and'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'only_coding_changes'}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'complete'}, {'id': '29', 'type': 'block', 'children': ['30', '41']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"Skipping transcript %s for variant %s because it\'s incomplete"'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '41', 'type': 'continue_statement', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '50']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '45'], 'value': 'and'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'not'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}; {'id': '50', 'type': 'block', 'children': ['51', '66']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '61', '62']}, {'id': '57', 'type': 'string', 'children': [], 'value': '"Skipping transcript %s for variant %s because it\'s not one of %d allowed"'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}; {'id': '66', 'type': 'continue_statement', 'children': []}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'effects'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'effect_on_transcript'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'effects'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'EffectCollection'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'effects'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'n_total_effects'}, {'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': 'effects'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'}; {'id': '100', 'type': 'string', 'children': [], 'value': '"Predicted total %d effects for variant %s"'}, {'id': '101', 'type': 'tuple', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'n_total_effects'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '107', '110']}, {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'only_coding_changes'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'effects'}; {'id': '110', 'type': 'else_clause', 'children': ['111']}, {'id': '111', 'type': 'block', 'children': ['112', '120', '134', '148', '161']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'nonsynonymous_coding_effects'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'effects'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'drop_silent_and_noncoding'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'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': 'logger'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127', '131', '132', '133']}; {'id': '126', 'type': 'string', 'children': [], 'value': '"Keeping %d/%d effects which affect protein coding sequence for %s: %s"'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'nonsynonymous_coding_effects'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'n_total_effects'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'nonsynonymous_coding_effects'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'usable_effects'}, {'id': '137', 'type': 'list_comprehension', 'children': ['138', '139', '142']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'effect'}, {'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'effect'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'nonsynonymous_coding_effects'}; {'id': '142', 'type': 'if_clause', 'children': ['143']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': 'is'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'effect'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'mutant_protein_sequence'}, {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '155', '159', '160']}; {'id': '154', 'type': 'string', 'children': [], 'value': '"Keeping %d effects with predictable AA sequences for %s: %s"'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'usable_effects'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'usable_effects'}, {'id': '161', 'type': 'return_statement', 'children': ['162']} | def predicted_effects_for_variant(
variant,
transcript_id_whitelist=None,
only_coding_changes=True):
effects = []
for transcript in variant.transcripts:
if only_coding_changes and not transcript.complete:
logger.info(
"Skipping transcript %s for variant %s because it's incomplete",
transcript.name,
variant)
continue
if transcript_id_whitelist and transcript.id not in transcript_id_whitelist:
logger.info(
"Skipping transcript %s for variant %s because it's not one of %d allowed",
transcript.name,
variant,
len(transcript_id_whitelist))
continue
effects.append(variant.effect_on_transcript(transcript))
effects = EffectCollection(effects)
n_total_effects = len(effects)
logger.info("Predicted total %d effects for variant %s" % (
n_total_effects,
variant))
if not only_coding_changes:
return effects
else:
nonsynonymous_coding_effects = effects.drop_silent_and_noncoding()
logger.info(
"Keeping %d/%d effects which affect protein coding sequence for %s: %s",
len(nonsynonymous_coding_effects),
n_total_effects,
variant,
nonsynonymous_coding_effects)
usable_effects = [
effect
for effect in nonsynonymous_coding_effects
if effect.mutant_protein_sequence is not None
]
logger.info(
"Keeping %d effects with predictable AA sequences for %s: %s",
len(usable_effects),
variant,
usable_effects)
return usable_effects |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_protein_sequences'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14', '19']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ProteinSequence'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ascending_sort_key'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '21', 'type': 'True', 'children': []} | def sort_protein_sequences(protein_sequences):
return list(
sorted(
protein_sequences,
key=ProteinSequence.ascending_sort_key,
reverse=True)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reads_generator_to_protein_sequences_generator'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'variant_and_overlapping_reads_generator'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'protein_sequence_length'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'PROTEIN_SEQUENCE_LENGTH'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'min_alt_rna_reads'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'MIN_ALT_RNA_READS'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'min_variant_sequence_coverage'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'MIN_VARIANT_SEQUENCE_COVERAGE'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'MIN_TRANSCRIPT_PREFIX_LENGTH'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'max_transcript_mismatches'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'MAX_REFERENCE_TRANSCRIPT_MISMATCHES'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'include_mismatches_after_variant'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'INCLUDE_MISMATCHES_AFTER_VARIANT'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_protein_sequences_per_variant'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'MAX_PROTEIN_SEQUENCES_PER_VARIANT'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_assembly'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'VARIANT_SEQUENCE_ASSEMBLY'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'for_statement', 'children': ['34', '37', '38']}; {'id': '34', 'type': 'tuple_pattern', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'variant_and_overlapping_reads_generator'}; {'id': '38', 'type': 'block', 'children': ['39', '55', '65', '72', '79', '89', '99', '135', '139', '241', '248']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'overlapping_transcript_ids'}; {'id': '42', 'type': 'list_comprehension', 'children': ['43', '46', '51']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'transcripts'}, {'id': '51', 'type': 'if_clause', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'is_protein_coding'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '61']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'alt'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'trim_variant'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'reads_grouped_by_allele'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'group_reads_by_allele'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ref_reads'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'reads_grouped_by_allele'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '88', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'alt_reads'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'reads_grouped_by_allele'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'alt'}; {'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': 'translations'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'translate_variant_reads'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '108', '111', '114', '117', '120', '123', '126', '129', '132']}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'variant_reads'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'alt_reads'}, {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'transcript_id_whitelist'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'protein_sequence_length'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'protein_sequence_length'}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'min_alt_rna_reads'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'min_alt_rna_reads'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'min_variant_sequence_coverage'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'min_variant_sequence_coverage'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'min_transcript_prefix_length'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'max_transcript_mismatches'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'max_transcript_mismatches'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'include_mismatches_after_variant'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'include_mismatches_after_variant'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_assembly'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'variant_sequence_assembly'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '138', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '139', 'type': 'for_statement', 'children': ['140', '143', '156']}; {'id': '140', 'type': 'tuple_pattern', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'equivalent_translations'}, {'id': '143', 'type': 'call', 'children': ['144', '155']}; {'id': '144', 'type': 'attribute', 'children': ['145', '154']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'translations'}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'key_fn'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'Translation'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'as_translation_key'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'block', 'children': ['157', '170', '183', '221', '234']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '163', '164']}, {'id': '159', 'type': 'pattern_list', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'alt_reads_supporting_protein_sequence'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'group_transcript_ids'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'group_gene_names'}, {'id': '163', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ProteinSequence'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': '_summarize_translations'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'equivalent_translations'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '182']}; {'id': '176', 'type': 'string', 'children': [], 'value': '"%s: %s alt reads supporting protein sequence (gene names = %s)"'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'alt_reads_supporting_protein_sequence'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'group_gene_names'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'protein_sequence'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ProteinSequence'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'from_translation_key'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194', '197', '200', '203', '206', '209', '212', '215']}, {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'translation_key'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'translations'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'equivalent_translations'}, {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'overlapping_reads'}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'alt_reads'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'alt_reads'}, {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ref_reads'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ref_reads'}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'alt_reads_supporting_protein_sequence'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'alt_reads_supporting_protein_sequence'}, {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'transcripts_supporting_protein_sequence'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'group_transcript_ids'}; {'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'transcripts_overlapping_variant'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'overlapping_transcript_ids'}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'gene'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'group_gene_names'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'}; {'id': '228', 'type': 'string', 'children': [], 'value': '"%s: protein sequence = %s"'}, {'id': '229', 'type': 'tuple', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'protein_sequence'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'amino_acids'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'protein_sequence'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sort_protein_sequences'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'yield', 'children': ['250']}; {'id': '250', 'type': 'expression_list', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'protein_sequences'}; {'id': '254', 'type': 'slice', 'children': ['255', '256']}, {'id': '255', 'type': 'colon', 'children': []} | def reads_generator_to_protein_sequences_generator(
variant_and_overlapping_reads_generator,
transcript_id_whitelist=None,
protein_sequence_length=PROTEIN_SEQUENCE_LENGTH,
min_alt_rna_reads=MIN_ALT_RNA_READS,
min_variant_sequence_coverage=MIN_VARIANT_SEQUENCE_COVERAGE,
min_transcript_prefix_length=MIN_TRANSCRIPT_PREFIX_LENGTH,
max_transcript_mismatches=MAX_REFERENCE_TRANSCRIPT_MISMATCHES,
include_mismatches_after_variant=INCLUDE_MISMATCHES_AFTER_VARIANT,
max_protein_sequences_per_variant=MAX_PROTEIN_SEQUENCES_PER_VARIANT,
variant_sequence_assembly=VARIANT_SEQUENCE_ASSEMBLY):
for (variant, overlapping_reads) in variant_and_overlapping_reads_generator:
overlapping_transcript_ids = [
t.id
for t in variant.transcripts
if t.is_protein_coding
]
_, ref, alt = trim_variant(variant)
overlapping_reads = list(overlapping_reads)
reads_grouped_by_allele = group_reads_by_allele(overlapping_reads)
ref_reads = reads_grouped_by_allele.get(ref, [])
alt_reads = reads_grouped_by_allele.get(alt, [])
translations = translate_variant_reads(
variant=variant,
variant_reads=alt_reads,
transcript_id_whitelist=transcript_id_whitelist,
protein_sequence_length=protein_sequence_length,
min_alt_rna_reads=min_alt_rna_reads,
min_variant_sequence_coverage=min_variant_sequence_coverage,
min_transcript_prefix_length=min_transcript_prefix_length,
max_transcript_mismatches=max_transcript_mismatches,
include_mismatches_after_variant=include_mismatches_after_variant,
variant_sequence_assembly=variant_sequence_assembly)
protein_sequences = []
for (key, equivalent_translations) in groupby(
translations, key_fn=Translation.as_translation_key).items():
alt_reads_supporting_protein_sequence, group_transcript_ids, group_gene_names = \
ProteinSequence._summarize_translations(equivalent_translations)
logger.info(
"%s: %s alt reads supporting protein sequence (gene names = %s)",
key,
len(alt_reads_supporting_protein_sequence),
group_gene_names)
protein_sequence = ProteinSequence.from_translation_key(
translation_key=key,
translations=equivalent_translations,
overlapping_reads=overlapping_reads,
alt_reads=alt_reads,
ref_reads=ref_reads,
alt_reads_supporting_protein_sequence=alt_reads_supporting_protein_sequence,
transcripts_supporting_protein_sequence=group_transcript_ids,
transcripts_overlapping_variant=overlapping_transcript_ids,
gene=list(group_gene_names))
logger.info("%s: protein sequence = %s" % (key, protein_sequence.amino_acids))
protein_sequences.append(protein_sequence)
protein_sequences = sort_protein_sequences(protein_sequences)
yield variant, protein_sequences[:max_protein_sequences_per_variant] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_variant_and_transcript'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'context_size'}; {'id': '8', 'type': 'block', 'children': ['9', '28', '47', '66', '83', '101']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '14']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'contains_start_codon'}; {'id': '14', 'type': 'block', 'children': ['15', '26']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '25']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"Expected transcript %s for variant %s to have start codon"'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '33']}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'contains_stop_codon'}, {'id': '33', 'type': 'block', 'children': ['34', '45']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"Expected transcript %s for variant %s to have stop codon"'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '52']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'protein_sequence'}; {'id': '52', 'type': 'block', 'children': ['53', '64']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Expected transript %s for variant %s to have protein sequence"'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sequence_key'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ReferenceSequenceKey'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'from_variant_and_transcript'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '77', '80']}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'context_size'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'context_size'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sequence_key'}; {'id': '86', 'type': 'None', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88', '99']}; {'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': 'logger'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"No sequence key for variant %s on transcript %s"'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'from_variant_and_transcript_and_sequence_key'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '110', '113']}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'variant'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'transcript'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'transcript'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sequence_key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sequence_key'} | def from_variant_and_transcript(
cls,
variant,
transcript,
context_size):
if not transcript.contains_start_codon:
logger.info(
"Expected transcript %s for variant %s to have start codon",
transcript.name,
variant)
return None
if not transcript.contains_stop_codon:
logger.info(
"Expected transcript %s for variant %s to have stop codon",
transcript.name,
variant)
return None
if not transcript.protein_sequence:
logger.info(
"Expected transript %s for variant %s to have protein sequence",
transcript.name,
variant)
return None
sequence_key = ReferenceSequenceKey.from_variant_and_transcript(
variant=variant,
transcript=transcript,
context_size=context_size)
if sequence_key is None:
logger.info(
"No sequence key for variant %s on transcript %s",
variant,
transcript.name)
return None
return cls.from_variant_and_transcript_and_sequence_key(
variant=variant,
transcript=transcript,
sequence_key=sequence_key) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'info'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'long_description'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'classifiers'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'license'}; {'id': '8', 'type': 'block', 'children': ['9', '17']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name_or_url'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '20', 'type': 'block', 'children': ['21', '29', '54', '90', '95', '107', '111', '125', '139', '143', '148', '152', '164', '180', '196', '208', '217', '233', '249', '253', '267', '286', '305', '334', '385']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_package'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'name_or_url'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '32']}; {'id': '30', 'type': 'not_operator', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '32', 'type': 'block', 'children': ['33', '53']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'secho'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '45', '48']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': 'u\'Invalid name or URL: "{name}"\''}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name_or_url'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fg'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'red'"}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '53', 'type': 'continue_statement', 'children': []}; {'id': '54', 'type': 'try_statement', 'children': ['55', '64']}, {'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': 'info'}, {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'info'"}; {'id': '64', 'type': 'except_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'}; {'id': '66', 'type': 'block', 'children': ['67', '89']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'secho'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '81', '84']}, {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'concatenated_string', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': 'u\'No versions found for "{0}". \''}, {'id': '75', 'type': 'string', 'children': [], 'value': "u'Skipping. . .'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fg'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'red'"}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '89', 'type': 'continue_statement', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'echo_header'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'name_or_url'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'summary'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'summary'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'Latest release: {version:12}'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'version'"}, {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'long_description'}, {'id': '127', 'type': 'block', 'children': ['128', '132']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'echo_download_summary'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'pattern_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'author_email'}, {'id': '157', 'type': 'expression_list', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'author'}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'author_email'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'string', 'children': [], 'value': "u'Author: {author:12}'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'dictionary_splat', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'locals'}, {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'if_statement', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'author_email'}; {'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': 'echo'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': "u'Author email: {author_email:12}'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'dictionary_splat', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'locals'}, {'id': '195', 'type': 'argument_list', 'children': []}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'pattern_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'maintainer'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'maintainer_email'}, {'id': '201', 'type': 'tuple', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'maintainer'}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'maintainer_email'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '212']}, {'id': '209', 'type': 'boolean_operator', 'children': ['210', '211'], 'value': 'or'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'maintainer'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'maintainer_email'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '216', 'type': 'argument_list', 'children': []}, {'id': '217', 'type': 'if_statement', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'maintainer'}, {'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': 'echo'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'string', 'children': [], 'value': "u'Maintainer: {maintainer:12}'"}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'dictionary_splat', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '232', 'type': 'argument_list', 'children': []}, {'id': '233', 'type': 'if_statement', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'maintainer_email'}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': "u'Maintainer email: {maintainer_email:12}'"}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'dictionary_splat', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '248', 'type': 'argument_list', 'children': []}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '252', 'type': 'argument_list', 'children': []}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'string', 'children': [], 'value': "u'PyPI URL: {pypi_url:12}'"}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'pypi_url'}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'package_url'}, {'id': '267', 'type': 'if_statement', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'home_page'}, {'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': 'echo'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'string', 'children': [], 'value': "u'Home Page: {home_page:12}'"}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'home_page'}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'home_page'}; {'id': '286', 'type': 'if_statement', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'docs_url'}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'string', 'children': [], 'value': "u'Documentation: {docs_url:12}'"}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'docs_url'}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'docs_url'}, {'id': '305', 'type': 'if_statement', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'classifiers'}, {'id': '307', 'type': 'block', 'children': ['308', '312', '317']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '311', 'type': 'argument_list', 'children': []}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'string', 'children': [], 'value': "u'Classifiers: '"}, {'id': '317', 'type': 'for_statement', 'children': ['318', '319', '326']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'each'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'string', 'children': [], 'value': "'classifiers'"}, {'id': '325', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'binary_operator', 'children': ['332', '333'], 'value': '+'}; {'id': '332', 'type': 'string', 'children': [], 'value': "'\\t'"}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '334', 'type': 'if_statement', 'children': ['335', '340']}, {'id': '335', 'type': 'boolean_operator', 'children': ['336', '337'], 'value': 'and'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'license'}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'license'}; {'id': '340', 'type': 'block', 'children': ['341', '345', '353', '378']}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'call', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '344', 'type': 'argument_list', 'children': []}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350']}, {'id': '349', 'type': 'string', 'children': [], 'value': "u'License: '"}; {'id': '350', 'type': 'keyword_argument', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'nl'}; {'id': '352', 'type': 'False', 'children': []}, {'id': '353', 'type': 'if_statement', 'children': ['354', '373']}; {'id': '354', 'type': 'boolean_operator', 'children': ['355', '365'], 'value': 'or'}, {'id': '355', 'type': 'comparison_operator', 'children': ['356', '364'], 'value': '>='}; {'id': '356', 'type': 'call', 'children': ['357', '362']}, {'id': '357', 'type': 'attribute', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'license'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}, {'id': '363', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '364', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '372'], 'value': '>'}; {'id': '366', 'type': 'call', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'license'}; {'id': '372', 'type': 'integer', 'children': [], 'value': '80'}, {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'call', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '377', 'type': 'argument_list', 'children': []}; {'id': '378', 'type': 'expression_statement', 'children': ['379']}, {'id': '379', 'type': 'call', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'license'}, {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'echo'} | def info(package, long_description, classifiers, license):
client = requests.Session()
for name_or_url in package:
package = get_package(name_or_url, client)
if not package:
secho(u'Invalid name or URL: "{name}"'.format(name=name_or_url),
fg='red', file=sys.stderr)
continue
try:
info = package.data['info']
except NotFoundError:
secho(u'No versions found for "{0}". '
u'Skipping. . .'.format(package.name),
fg='red', file=sys.stderr)
continue
echo_header(name_or_url)
if package.summary:
echo(package.summary)
echo()
echo('Latest release: {version:12}'.format(version=info['version']))
if long_description:
echo()
echo(package.description)
echo()
echo_download_summary(package)
echo()
author, author_email = package.author, package.author_email
if author:
echo(u'Author: {author:12}'.format(**locals()))
if author_email:
echo(u'Author email: {author_email:12}'.format(**locals()))
maintainer, maintainer_email = (package.maintainer,
package.maintainer_email)
if maintainer or maintainer_email:
echo()
if maintainer:
echo(u'Maintainer: {maintainer:12}'.format(**locals()))
if maintainer_email:
echo(u'Maintainer email: {maintainer_email:12}'.format(**locals()))
echo()
echo(u'PyPI URL: {pypi_url:12}'.format(pypi_url=package.package_url))
if package.home_page:
echo(u'Home Page: {home_page:12}'.format(
home_page=package.home_page))
if package.docs_url:
echo(u'Documentation: {docs_url:12}'.format(
docs_url=package.docs_url))
if classifiers:
echo()
echo(u'Classifiers: ')
for each in info.get('classifiers', []):
echo('\t' + each)
if license and package.license:
echo()
echo(u'License: ', nl=False)
if package.license.find('\n') >= 0 or len(package.license) > 80:
echo()
echo(package.license)
echo() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'install_packages'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'packages'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'what_for'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'for a complete setup to work properly'"}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15', '22', '31', '193']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Try to install .deb packages given by list.\n Return True, if packages could be installed or are installed already, or if\n they cannot be installed but the user gives feedback to continue.\n Else return False.\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'non_installed_packages'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_non_installed'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'packages'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'packages_str'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'non_installed_packages'}, {'id': '31', 'type': 'if_statement', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'non_installed_packages'}, {'id': '33', 'type': 'block', 'children': ['34', '47', '51', '55', '59', '161', '172']}; {'id': '34', 'type': 'with_statement', 'children': ['35', '40']}, {'id': '35', 'type': 'with_clause', 'children': ['36']}; {'id': '36', 'type': 'with_item', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'quiet'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dpkg'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_has_dpkg'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'hint'}; {'id': '50', 'type': 'string', 'children': [], 'value': "' (You may have to install them manually)'"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'do_install'}; {'id': '54', 'type': 'False', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'go_on'}; {'id': '58', 'type': 'True', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '61', '119']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dpkg'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '67', '72']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_is_sudoer'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'Want to install dpkg packages'"}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'do_install'}, {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74', '78', '101', '105']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'do_install'}, {'id': '77', 'type': 'False', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'yellow'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'list', 'children': ['90', '91', '95'], 'value': '[\n \'This deb packages are missing to be installed\',\n flo("{what_for}: "), \', \'.join(non_installed_packages),\n ]'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'This deb packages are missing to be installed'"}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'flo'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"{what_for}: "'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'non_installed_packages'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'question'}; {'id': '104', 'type': 'string', 'children': [], 'value': "' Continue anyway?'"}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'go_on'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'query_yes_no'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '116']}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '115'], 'value': '+'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '+'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'hint'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'question'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'no'"}, {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121', '125', '147']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'do_install'}; {'id': '124', 'type': 'False', 'children': []}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'yellow'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'list', 'children': ['137', '141'], 'value': "[\n flo('Required {what_for}: '),\n ', '.join(non_installed_packages),\n ]"}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'flo'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Required {what_for}: '"}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'non_installed_packages'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'go_on'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'query_yes_no'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '158']}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '+'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '+'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'hint'}, {'id': '157', 'type': 'string', 'children': [], 'value': "' Continue?'"}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'yes'"}, {'id': '161', 'type': 'if_statement', 'children': ['162', '164']}; {'id': '162', 'type': 'not_operator', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'go_on'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'Abort'"}; {'id': '172', 'type': 'if_statement', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'do_install'}; {'id': '174', 'type': 'block', 'children': ['175', '182']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'flo'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'sudo apt-get install {packages_str}'"}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '192'], 'value': '=='}; {'id': '186', 'type': 'attribute', 'children': ['187', '191']}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'return_code'}; {'id': '192', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '193', 'type': 'return_statement', 'children': ['194']} | def install_packages(packages,
what_for='for a complete setup to work properly'):
'''Try to install .deb packages given by list.
Return True, if packages could be installed or are installed already, or if
they cannot be installed but the user gives feedback to continue.
Else return False.
'''
res = True
non_installed_packages = _non_installed(packages)
packages_str = ' '.join(non_installed_packages)
if non_installed_packages:
with quiet():
dpkg = _has_dpkg()
hint = ' (You may have to install them manually)'
do_install = False
go_on = True
if dpkg:
if _is_sudoer('Want to install dpkg packages'):
do_install = True
else:
do_install is False
info = yellow(' '.join([
'This deb packages are missing to be installed',
flo("{what_for}: "), ', '.join(non_installed_packages),
]))
question = ' Continue anyway?'
go_on = query_yes_no(info + hint + question, default='no')
else:
do_install = False
info = yellow(' '.join([
flo('Required {what_for}: '),
', '.join(non_installed_packages),
]))
go_on = query_yes_no(info + hint + ' Continue?', default='yes')
if not go_on:
sys.exit('Abort')
if do_install:
command = flo('sudo apt-get install {packages_str}')
res = run(command).return_code == 0
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scan'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '80'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'https'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'max_size'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '65535'}; {'id': '20', 'type': 'block', 'children': ['21', '27', '33', '40', '60', '73', '89', '131', '143', '157', '164', '175', '187', '238', '365', '371', '383', '414', '425']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '49', '52', '55']}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'closed'"}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'durations'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '62', 'type': 'block', 'children': ['63', '67']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'code'"}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'dns'"}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '88', 'type': 'argument_list', 'children': []}, {'id': '89', 'type': 'try_statement', 'children': ['90', '118']}; {'id': '90', 'type': 'block', 'children': ['91', '100', '106']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'hostip'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'gethostbyname'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'ip'"}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'hostip'}; {'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': 'ends'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'dns'"}, {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'except_clause', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'gaierror'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'raise_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ScanFailed'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'DNS Lookup failed'"}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'connect'"}; {'id': '136', 'type': 'call', 'children': ['137', '142']}, {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'network_socket'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'AF_INET'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'SOCK_STREAM'}, {'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': 'network_socket'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'settimeout'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'result_connection'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'network_socket'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'connect_ex'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'tuple', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'hostip'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'connect'"}; {'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': 'datetime'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '186', 'type': 'argument_list', 'children': []}, {'id': '187', 'type': 'if_statement', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'https'}, {'id': '189', 'type': 'block', 'children': ['190', '202', '226']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'ssl'"}, {'id': '195', 'type': 'call', 'children': ['196', '201']}; {'id': '196', 'type': 'attribute', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'try_statement', 'children': ['203', '213']}, {'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': 'network_socket'}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ssl'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'wrap_socket'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'network_socket'}, {'id': '213', 'type': 'except_clause', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'raise_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ScanFailed'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'string', 'children': [], 'value': "'SSL socket timeout'"}, {'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'ssl'"}, {'id': '231', 'type': 'call', 'children': ['232', '237']}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '237', 'type': 'argument_list', 'children': []}; {'id': '238', 'type': 'if_statement', 'children': ['239', '244']}, {'id': '239', 'type': 'boolean_operator', 'children': ['240', '243'], 'value': 'and'}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': '=='}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'result_connection'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '244', 'type': 'block', 'children': ['245', '257', '275', '297', '306', '318', '325', '353']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '250']}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '249', 'type': 'string', 'children': [], 'value': "'request'"}; {'id': '250', 'type': 'call', 'children': ['251', '256']}, {'id': '251', 'type': 'attribute', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '256', 'type': 'argument_list', 'children': []}, {'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': 'network_socket'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '273']}; {'id': '264', 'type': 'attribute', 'children': ['265', '272']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'string', 'children': [], 'value': '"GET {0} HTTP/1.0\\r\\nHost: {1}\\r\\n\\r\\n"'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '275', 'type': 'if_statement', 'children': ['276', '277', '287']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'max_size'}, {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'network_socket'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'recv'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'max_size'}, {'id': '287', 'type': 'else_clause', 'children': ['288']}; {'id': '288', 'type': 'block', 'children': ['289']}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'network_socket'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'recv'}; {'id': '296', 'type': 'argument_list', 'children': []}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '302', 'type': 'call', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '315']}; {'id': '314', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '317', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '323']}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '322', 'type': 'string', 'children': [], 'value': "'response'"}, {'id': '323', 'type': 'parenthesized_expression', 'children': ['324'], 'value': '()'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '325', 'type': 'try_statement', 'children': ['326', '349']}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '332']}, {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '331', 'type': 'string', 'children': [], 'value': "'code'"}; {'id': '332', 'type': 'call', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'subscript', 'children': ['336', '348']}; {'id': '336', 'type': 'call', 'children': ['337', '347']}, {'id': '337', 'type': 'attribute', 'children': ['338', '346']}; {'id': '338', 'type': 'subscript', 'children': ['339', '345']}, {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '345', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '347', 'type': 'argument_list', 'children': []}; {'id': '348', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '349', 'type': 'except_clause', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'pass_statement', 'children': []}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '358']}, {'id': '355', 'type': 'subscript', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '357', 'type': 'string', 'children': [], 'value': "'request'"}; {'id': '358', 'type': 'call', 'children': ['359', '364']}, {'id': '359', 'type': 'attribute', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '364', 'type': 'argument_list', 'children': []}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '370']}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'network_socket'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '370', 'type': 'argument_list', 'children': []}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '376']}, {'id': '373', 'type': 'subscript', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '375', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '376', 'type': 'call', 'children': ['377', '382']}, {'id': '377', 'type': 'attribute', 'children': ['378', '381']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '382', 'type': 'argument_list', 'children': []}, {'id': '383', 'type': 'for_statement', 'children': ['384', '385', '390']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'duration'}, {'id': '385', 'type': 'call', 'children': ['386', '389']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '389', 'type': 'argument_list', 'children': []}; {'id': '390', 'type': 'block', 'children': ['391']}, {'id': '391', 'type': 'if_statement', 'children': ['392', '399']}; {'id': '392', 'type': 'comparison_operator', 'children': ['393', '394'], 'value': 'in'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '394', 'type': 'call', 'children': ['395', '398']}, {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '398', 'type': 'argument_list', 'children': []}, {'id': '399', 'type': 'block', 'children': ['400']}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}, {'id': '401', 'type': 'assignment', 'children': ['402', '407']}; {'id': '402', 'type': 'subscript', 'children': ['403', '406']}, {'id': '403', 'type': 'subscript', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '405', 'type': 'string', 'children': [], 'value': "'durations'"}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'duration'}, {'id': '407', 'type': 'binary_operator', 'children': ['408', '411'], 'value': '-'}; {'id': '408', 'type': 'subscript', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'duration'}, {'id': '411', 'type': 'subscript', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '414', 'type': 'if_statement', 'children': ['415', '418']}, {'id': '415', 'type': 'comparison_operator', 'children': ['416', '417'], 'value': '=='}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'result_connection'}, {'id': '417', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '418', 'type': 'block', 'children': ['419']}, {'id': '419', 'type': 'expression_statement', 'children': ['420']}; {'id': '420', 'type': 'assignment', 'children': ['421', '424']}, {'id': '421', 'type': 'subscript', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '423', 'type': 'string', 'children': [], 'value': "'state'"}; {'id': '424', 'type': 'string', 'children': [], 'value': "'open'"}, {'id': '425', 'type': 'return_statement', 'children': ['426']} | def scan(host, port=80, url=None, https=False, timeout=1, max_size=65535):
starts = OrderedDict()
ends = OrderedDict()
port = int(port)
result = dict(
host=host, port=port, state='closed', durations=OrderedDict()
)
if url:
timeout = 1
result['code'] = None
starts['all'] = starts['dns'] = datetime.datetime.now()
try:
hostip = socket.gethostbyname(host)
result['ip'] = hostip
ends['dns'] = datetime.datetime.now()
except socket.gaierror:
raise ScanFailed('DNS Lookup failed', result=result)
starts['connect'] = datetime.datetime.now()
network_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
network_socket.settimeout(timeout)
result_connection = network_socket.connect_ex((hostip, port))
ends['connect'] = datetime.datetime.now()
if https:
starts['ssl'] = datetime.datetime.now()
try:
network_socket = ssl.wrap_socket(network_socket)
except socket.timeout:
raise ScanFailed('SSL socket timeout', result=result)
ends['ssl'] = datetime.datetime.now()
if result_connection == 0 and url:
starts['request'] = datetime.datetime.now()
network_socket.send(
"GET {0} HTTP/1.0\r\nHost: {1}\r\n\r\n".format(
url, host
).encode('ascii'))
if max_size:
data = network_socket.recv(max_size)
else:
data = network_socket.recv()
result['length'] = len(data)
data = data.decode('ascii', errors='ignore')
result['response'] = (data)
try:
result['code'] = int(data.split('\n')[0].split()[1])
except IndexError:
pass
ends['request'] = datetime.datetime.now()
network_socket.close()
ends['all'] = datetime.datetime.now()
for duration in starts.keys():
if duration in ends.keys():
result['durations'][duration] = ends[duration] - starts[duration]
if result_connection == 0:
result['state'] = 'open'
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '45']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'redirect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'permanent'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'locale_prefix'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'vary'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cache_timeout'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'decorators'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 're_flags'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'to_args'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'to_kwargs'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'prepend_locale'}, {'id': '41', 'type': 'True', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'merge_query'}; {'id': '44', 'type': 'False', 'children': []}, {'id': '45', 'type': 'block', 'children': ['46', '59', '77', '91', '95', '110', '136', '161', '429', '457']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '48', '53']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'permanent'}; {'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': 'redirect_class'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'HttpResponsePermanentRedirect'}, {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'redirect_class'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'HttpResponseRedirect'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'locale_prefix'}, {'id': '61', 'type': 'block', 'children': ['62', '71']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'^/'"}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '+'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'LOCALE_RE'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 're_flags'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '90'], 'value': '+'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'(?{})'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 're_flags'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'view_decorators'}; {'id': '94', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cache_timeout'}; {'id': '98', 'type': 'None', 'children': []}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'view_decorators'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'cache_control_expires'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cache_timeout'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'vary'}; {'id': '112', 'type': 'block', 'children': ['113', '125']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '119']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'vary'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'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': 'vary'}, {'id': '123', 'type': 'list', 'children': ['124'], 'value': '[vary]'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'vary'}, {'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': 'view_decorators'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'vary_on_headers'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'list_splat', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'vary'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'decorators'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'if_statement', 'children': ['140', '144', '152']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'decorators'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'view_decorators'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'decorators'}; {'id': '152', 'type': 'else_clause', 'children': ['153']}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'view_decorators'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'decorators'}, {'id': '161', 'type': 'function_definition', 'children': ['162', '163', '169']}; {'id': '162', 'type': 'function_name', 'children': [], 'value': '_view'}, {'id': '163', 'type': 'parameters', 'children': ['164', '165', '167']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '165', 'type': 'list_splat_pattern', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '167', 'type': 'dictionary_splat_pattern', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '169', 'type': 'block', 'children': ['170', '188', '198', '221', '264', '292', '315', '386', '400', '424']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '173', 'type': 'dictionary_comprehension', 'children': ['174', '179']}; {'id': '174', 'type': 'pair', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '176', 'type': 'boolean_operator', 'children': ['177', '178'], 'value': 'or'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '178', 'type': 'string', 'children': [], 'value': "''"}, {'id': '179', 'type': 'for_in_clause', 'children': ['180', '183']}; {'id': '180', 'type': 'pattern_list', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '187', 'type': 'argument_list', 'children': []}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '191', 'type': 'list_comprehension', 'children': ['192', '195']}; {'id': '192', 'type': 'boolean_operator', 'children': ['193', '194'], 'value': 'or'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '194', 'type': 'string', 'children': [], 'value': "''"}, {'id': '195', 'type': 'for_in_clause', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '203', '215']}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'to'}, {'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': 'to_value'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '213']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '211', 'type': 'list_splat', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '213', 'type': 'dictionary_splat', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '215', 'type': 'else_clause', 'children': ['216']}; {'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': 'to_value'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '235', '240']}; {'id': '222', 'type': 'boolean_operator', 'children': ['223', '229'], 'value': 'or'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'to_value'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'HTTP_RE'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'to_value'}, {'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': 'redirect_url'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'to_value'}; {'id': '240', 'type': 'else_clause', 'children': ['241']}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'try_statement', 'children': ['243', '257']}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251', '254']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'to_value'}, {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'to_args'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'to_kwargs'}, {'id': '257', 'type': 'except_clause', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}, {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'to_value'}; {'id': '264', 'type': 'if_statement', 'children': ['265', '280']}, {'id': '265', 'type': 'boolean_operator', 'children': ['266', '274'], 'value': 'and'}; {'id': '266', 'type': 'boolean_operator', 'children': ['267', '268'], 'value': 'and'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'prepend_locale'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'string', 'children': [], 'value': "'locale'"}; {'id': '280', 'type': 'block', 'children': ['281']}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '+'}, {'id': '285', 'type': 'string', 'children': [], 'value': "'/{locale}'"}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'lstrip'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '292', 'type': 'if_statement', 'children': ['293', '296']}, {'id': '293', 'type': 'boolean_operator', 'children': ['294', '295'], 'value': 'or'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '296', 'type': 'block', 'children': ['297']}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'strip_tags'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'call', 'children': ['304', '310']}; {'id': '304', 'type': 'attribute', 'children': ['305', '309']}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'force_text'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '313']}, {'id': '311', 'type': 'list_splat', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '313', 'type': 'dictionary_splat', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '315', 'type': 'if_statement', 'children': ['316', '317', '364', '380']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'if_statement', 'children': ['319', '320', '352']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'merge_query'}; {'id': '320', 'type': 'block', 'children': ['321', '335', '342']}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'req_query'}; {'id': '324', 'type': 'call', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'parse_qs'}; {'id': '326', 'type': 'argument_list', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '333']}; {'id': '328', 'type': 'attribute', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'META'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'string', 'children': [], 'value': "'QUERY_STRING'"}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '340']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'req_query'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'assignment', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'querystring'}, {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'urlencode'}, {'id': '347', 'type': 'argument_list', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'req_query'}, {'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'doseq'}, {'id': '351', 'type': 'True', 'children': []}; {'id': '352', 'type': 'else_clause', 'children': ['353']}, {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'querystring'}, {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'urlencode'}, {'id': '359', 'type': 'argument_list', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '361', 'type': 'keyword_argument', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'doseq'}, {'id': '363', 'type': 'True', 'children': []}; {'id': '364', 'type': 'elif_clause', 'children': ['365', '368']}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '367'], 'value': 'is'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '367', 'type': 'None', 'children': []}; {'id': '368', 'type': 'block', 'children': ['369']}, {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'assignment', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'querystring'}; {'id': '372', 'type': 'call', 'children': ['373', '378']}, {'id': '373', 'type': 'attribute', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'META'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}, {'id': '379', 'type': 'string', 'children': [], 'value': "'QUERY_STRING'"}; {'id': '380', 'type': 'else_clause', 'children': ['381']}, {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'assignment', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'querystring'}, {'id': '385', 'type': 'string', 'children': [], 'value': "''"}; {'id': '386', 'type': 'if_statement', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'querystring'}; {'id': '388', 'type': 'block', 'children': ['389']}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'assignment', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '392', 'type': 'call', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'string', 'children': [], 'value': "'?'"}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'list', 'children': ['398', '399'], 'value': '[redirect_url, querystring]'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'querystring'}; {'id': '400', 'type': 'if_statement', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '402', 'type': 'block', 'children': ['403']}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '406', '414']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '406', 'type': 'ERROR', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'if'}; {'id': '408', 'type': 'call', 'children': ['409', '412']}, {'id': '409', 'type': 'attribute', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'PROTOCOL_RELATIVE_RE'}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '412', 'type': 'argument_list', 'children': ['413']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '414', 'type': 'assignment', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}; {'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '+'}, {'id': '417', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '418', 'type': 'call', 'children': ['419', '422']}, {'id': '419', 'type': 'attribute', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'lstrip'}; {'id': '422', 'type': 'argument_list', 'children': ['423']}, {'id': '423', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '424', 'type': 'return_statement', 'children': ['425']}, {'id': '425', 'type': 'call', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'redirect_class'}, {'id': '427', 'type': 'argument_list', 'children': ['428']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'redirect_url'}, {'id': '429', 'type': 'try_statement', 'children': ['430', '445']}; {'id': '430', 'type': 'block', 'children': ['431']}, {'id': '431', 'type': 'for_statement', 'children': ['432', '433', '437']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'decorator'}, {'id': '433', 'type': 'call', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '435', 'type': 'argument_list', 'children': ['436']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'view_decorators'}, {'id': '437', 'type': 'block', 'children': ['438']}; {'id': '438', 'type': 'expression_statement', 'children': ['439']}, {'id': '439', 'type': 'assignment', 'children': ['440', '441']}; {'id': '440', 'type': 'identifier', 'children': [], 'value': '_view'}, {'id': '441', 'type': 'call', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'decorator'}, {'id': '443', 'type': 'argument_list', 'children': ['444']}; {'id': '444', 'type': 'identifier', 'children': [], 'value': '_view'}, {'id': '445', 'type': 'except_clause', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '447', 'type': 'block', 'children': ['448']}; {'id': '448', 'type': 'expression_statement', 'children': ['449']}, {'id': '449', 'type': 'call', 'children': ['450', '453']}; {'id': '450', 'type': 'attribute', 'children': ['451', '452']}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '453', 'type': 'argument_list', 'children': ['454']}; {'id': '454', 'type': 'concatenated_string', 'children': ['455', '456']}, {'id': '455', 'type': 'string', 'children': [], 'value': "'decorators not iterable or does not contain '"}; {'id': '456', 'type': 'string', 'children': [], 'value': "'callable items'"}, {'id': '457', 'type': 'return_statement', 'children': ['458']}; {'id': '458', 'type': 'call', 'children': ['459', '460']}, {'id': '459', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '460', 'type': 'argument_list', 'children': ['461', '462', '463']}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '462', 'type': 'identifier', 'children': [], 'value': '_view'}, {'id': '463', 'type': 'keyword_argument', 'children': ['464', '465']}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '465', 'type': 'identifier', 'children': [], 'value': 'name'} | def redirect(pattern, to, permanent=True, locale_prefix=True, anchor=None, name=None,
query=None, vary=None, cache_timeout=12, decorators=None, re_flags=None,
to_args=None, to_kwargs=None, prepend_locale=True, merge_query=False):
if permanent:
redirect_class = HttpResponsePermanentRedirect
else:
redirect_class = HttpResponseRedirect
if locale_prefix:
pattern = pattern.lstrip('^/')
pattern = LOCALE_RE + pattern
if re_flags:
pattern = '(?{})'.format(re_flags) + pattern
view_decorators = []
if cache_timeout is not None:
view_decorators.append(cache_control_expires(cache_timeout))
if vary:
if isinstance(vary, basestring):
vary = [vary]
view_decorators.append(vary_on_headers(*vary))
if decorators:
if callable(decorators):
view_decorators.append(decorators)
else:
view_decorators.extend(decorators)
def _view(request, *args, **kwargs):
kwargs = {k: v or '' for k, v in kwargs.items()}
args = [x or '' for x in args]
if callable(to):
to_value = to(request, *args, **kwargs)
else:
to_value = to
if to_value.startswith('/') or HTTP_RE.match(to_value):
redirect_url = to_value
else:
try:
redirect_url = reverse(to_value, args=to_args, kwargs=to_kwargs)
except NoReverseMatch:
redirect_url = to_value
if prepend_locale and redirect_url.startswith('/') and kwargs.get('locale'):
redirect_url = '/{locale}' + redirect_url.lstrip('/')
if args or kwargs:
redirect_url = strip_tags(force_text(redirect_url).format(*args, **kwargs))
if query:
if merge_query:
req_query = parse_qs(request.META.get('QUERY_STRING'))
req_query.update(query)
querystring = urlencode(req_query, doseq=True)
else:
querystring = urlencode(query, doseq=True)
elif query is None:
querystring = request.META.get('QUERY_STRING')
else:
querystring = ''
if querystring:
redirect_url = '?'.join([redirect_url, querystring])
if anchor:
redirect_url = '
if PROTOCOL_RELATIVE_RE.match(redirect_url):
redirect_url = '/' + redirect_url.lstrip('/')
return redirect_class(redirect_url)
try:
for decorator in reversed(view_decorators):
_view = decorator(_view)
except TypeError:
log.exception('decorators not iterable or does not contain '
'callable items')
return url(pattern, _view, name=name) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'FD'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '40', '69', '105', '140', '255', '277']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Verbose'}; {'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': 'string', 'children': [], 'value': '"Finite Difference Solution Technique"'}; {'id': '16', 'type': 'try_statement', 'children': ['17', '22']}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'qs'}; {'id': '22', 'type': 'except_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24', '36']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'qs'}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'delete_statement', 'children': ['37']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '55', '66']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '54'], 'value': '/'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '54', 'type': 'float', 'children': [], 'value': '2.'}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '*'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '59', 'type': 'subscript', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'qs'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '75']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '=='}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dimension'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'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': 'y'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '91', '102']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '90'], 'value': '/'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dy'}; {'id': '90', 'type': 'float', 'children': [], 'value': '2.'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '95'], 'value': '*'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dy'}, {'id': '95', 'type': 'subscript', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'qs'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dy'}, {'id': '105', 'type': 'try_statement', 'children': ['106', '111']}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'Solver'}, {'id': '111', 'type': 'except_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '117', '131']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Solver'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'configGet'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'string', 'children': [], 'value': '"string"'}, {'id': '129', 'type': 'string', 'children': [], 'value': '"numerical"'}; {'id': '130', 'type': 'string', 'children': [], 'value': '"Solver"'}, {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': '"No solver defined!"'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '144', 'type': 'block', 'children': ['145', '158', '231']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'iterative_ConvergenceTolerance'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'configGet'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157']}, {'id': '155', 'type': 'string', 'children': [], 'value': '"float"'}; {'id': '156', 'type': 'string', 'children': [], 'value': '"numerical"'}, {'id': '157', 'type': 'string', 'children': [], 'value': '"ConvergenceTolerance"'}; {'id': '158', 'type': 'try_statement', 'children': ['159', '209']}, {'id': '159', 'type': 'block', 'children': ['160', '176']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'configGet'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '173']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"float"'}, {'id': '171', 'type': 'string', 'children': [], 'value': '"input"'}; {'id': '172', 'type': 'string', 'children': [], 'value': '"ElasticThickness"'}, {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'optional'}, {'id': '175', 'type': 'False', 'children': []}; {'id': '176', 'type': 'if_statement', 'children': ['177', '182', '203']}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': 'is'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '181', 'type': 'None', 'children': []}; {'id': '182', 'type': 'block', 'children': ['183', '197']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'Tepath'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'configGet'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193', '194']}, {'id': '191', 'type': 'string', 'children': [], 'value': '"string"'}; {'id': '192', 'type': 'string', 'children': [], 'value': '"input"'}, {'id': '193', 'type': 'string', 'children': [], 'value': '"ElasticThickness"'}; {'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '196', 'type': 'False', 'children': []}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'Te'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'Tepath'}, {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'Tepath'}; {'id': '208', 'type': 'None', 'children': []}, {'id': '209', 'type': 'except_clause', 'children': ['210']}; {'id': '210', 'type': 'block', 'children': ['211', '225']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'Tepath'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'configGet'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '220', '221', '222']}, {'id': '219', 'type': 'string', 'children': [], 'value': '"string"'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"input"'}, {'id': '221', 'type': 'string', 'children': [], 'value': '"ElasticThickness"'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '224', 'type': 'False', 'children': []}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'Te'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'Tepath'}, {'id': '231', 'type': 'if_statement', 'children': ['232', '237']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': 'is'}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'Te'}; {'id': '236', 'type': 'None', 'children': []}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '244', '246']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '243'], 'value': 'is'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'coeff_matrix'}, {'id': '243', 'type': 'None', 'children': []}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'pass_statement', 'children': []}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'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': 'sys'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"No input elastic thickness or coefficient matrix supplied."'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '264', '271']}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '263'], 'value': '=='}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'Tepath'}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '271', 'type': 'else_clause', 'children': ['272']}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'Tepath'}; {'id': '276', 'type': 'None', 'children': []}, {'id': '277', 'type': 'if_statement', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'Tepath'}, {'id': '279', 'type': 'block', 'children': ['280', '296', '348']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'loadFile'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'close_on_fail'}, {'id': '295', 'type': 'False', 'children': []}; {'id': '296', 'type': 'if_statement', 'children': ['297', '302']}, {'id': '297', 'type': 'comparison_operator', 'children': ['298', '301'], 'value': 'is'}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'Te'}, {'id': '301', 'type': 'None', 'children': []}; {'id': '302', 'type': 'block', 'children': ['303', '308', '313', '318']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'string', 'children': [], 'value': '"Requested Te file is provided but cannot be located."'}; {'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': 'string', 'children': [], 'value': '"No scalar elastic thickness is provided in configuration file"'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'string', 'children': [], 'value': '"(Typo in path to input Te grid?)"'}; {'id': '318', 'type': 'if_statement', 'children': ['319', '324', '335']}, {'id': '319', 'type': 'comparison_operator', 'children': ['320', '323'], 'value': 'is'}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'coeff_matrix'}, {'id': '323', 'type': 'None', 'children': []}; {'id': '324', 'type': 'block', 'children': ['325', '330']}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'string', 'children': [], 'value': '"But a coefficient matrix has been found."'}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'string', 'children': [], 'value': '"Calculations will be carried forward using it."'}, {'id': '335', 'type': 'else_clause', 'children': ['336']}; {'id': '336', 'type': 'block', 'children': ['337', '342']}, {'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': 'string', 'children': [], 'value': '"Exiting."'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '347', 'type': 'argument_list', 'children': []}; {'id': '348', 'type': 'if_statement', 'children': ['349', '356']}, {'id': '349', 'type': 'call', 'children': ['350', '355']}; {'id': '350', 'type': 'attribute', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'Te'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '355', 'type': 'argument_list', 'children': []}; {'id': '356', 'type': 'block', 'children': ['357']}, {'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': 'self'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'TeArraySizeCheck'} | def FD(self):
if self.Verbose:
print("Finite Difference Solution Technique")
try:
self.qs
except:
self.qs = self.q0.copy()
del self.q0
self.x = np.arange(self.dx/2., self.dx * self.qs.shape[0], self.dx)
if self.dimension == 2:
self.y = np.arange(self.dy/2., self.dy * self.qs.shape[1], self.dy)
try:
self.Solver
except:
if self.filename:
self.Solver = self.configGet("string", "numerical", "Solver")
else:
sys.exit("No solver defined!")
if self.filename:
self.iterative_ConvergenceTolerance = self.configGet("float", "numerical", "ConvergenceTolerance")
try:
self.Te = self.configGet("float", "input", "ElasticThickness", optional=False)
if self.Te is None:
Tepath = self.configGet("string", "input", "ElasticThickness", optional=False)
self.Te = Tepath
else:
Tepath = None
except:
Tepath = self.configGet("string", "input", "ElasticThickness", optional=False)
self.Te = Tepath
if self.Te is None:
if self.coeff_matrix is not None:
pass
else:
sys.exit("No input elastic thickness or coefficient matrix supplied.")
if type(self.Te) == str:
Tepath = self.Te
else:
Tepath = None
if Tepath:
self.Te = self.loadFile(self.Te, close_on_fail = False)
if self.Te is None:
print("Requested Te file is provided but cannot be located.")
print("No scalar elastic thickness is provided in configuration file")
print("(Typo in path to input Te grid?)")
if self.coeff_matrix is not None:
print("But a coefficient matrix has been found.")
print("Calculations will be carried forward using it.")
else:
print("Exiting.")
sys.exit()
if self.Te.any():
self.TeArraySizeCheck() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'SAS_NG'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '69', '224', '232', '247', '251', '298', '321', '452']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '10', 'type': 'block', 'children': ['11', '24', '40', '56']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Te'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'configGet'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"float"'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"input"'}, {'id': '23', 'type': 'string', 'children': [], 'value': '"ElasticThickness"'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'latlon'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'configGet'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36', '37']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"string"'}, {'id': '35', 'type': 'string', 'children': [], 'value': '"numerical2D"'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"latlon"'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'optional'}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'PlanetaryRadius'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'configGet'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"float"'}, {'id': '51', 'type': 'string', 'children': [], 'value': '"numerical2D"'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"PlanetaryRadius"'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'optional'}, {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dimension'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'import_from_statement', 'children': ['64', '67']}; {'id': '64', 'type': 'dotted_name', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'special'}, {'id': '67', 'type': 'dotted_name', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'kei'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '75', '141']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '=='}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dimension'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'try_statement', 'children': ['77', '86']}, {'id': '77', 'type': 'block', 'children': ['78', '82']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '86', 'type': 'except_clause', 'children': ['87']}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'if_statement', 'children': ['89', '98', '123']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '97'], 'value': '=='}; {'id': '90', 'type': 'subscript', 'children': ['91', '96']}, {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'block', 'children': ['99', '111']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '104', 'type': 'subscript', 'children': ['105', '108', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '108', 'type': 'slice', 'children': ['109']}, {'id': '109', 'type': 'colon', 'children': []}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '116', 'type': 'subscript', 'children': ['117', '120', '122']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '120', 'type': 'slice', 'children': ['121']}, {'id': '121', 'type': 'colon', 'children': []}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '+'}; {'id': '132', 'type': 'string', 'children': [], 'value': '"For 1D (ungridded) SAS_NG configuration file, need [x,w] array. Your dimensions are: "'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'try_statement', 'children': ['144', '157']}; {'id': '144', 'type': 'block', 'children': ['145', '149', '153']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '157', 'type': 'except_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'if_statement', 'children': ['160', '169', '206']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '168'], 'value': '=='}, {'id': '161', 'type': 'subscript', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'q0'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '169', 'type': 'block', 'children': ['170', '182', '194']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '175', 'type': 'subscript', 'children': ['176', '179', '181']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '179', 'type': 'slice', 'children': ['180']}; {'id': '180', 'type': 'colon', 'children': []}, {'id': '181', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', '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': 'subscript', 'children': ['188', '191', '193']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '191', 'type': 'slice', 'children': ['192']}; {'id': '192', 'type': 'colon', 'children': []}, {'id': '193', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '199', 'type': 'subscript', 'children': ['200', '203', '205']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '203', 'type': 'slice', 'children': ['204']}; {'id': '204', 'type': 'colon', 'children': []}, {'id': '205', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '206', 'type': 'else_clause', 'children': ['207']}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '+'}, {'id': '215', 'type': 'string', 'children': [], 'value': '"For 2D (ungridded) SAS_NG configuration file, need [x,y,w] array. Your dimensions are: "'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '232', 'type': 'if_statement', 'children': ['233', '238']}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '237'], 'value': '=='}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'dimension'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '238', 'type': 'block', 'children': ['239']}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '247', 'type': 'delete_statement', 'children': ['248']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'q0'}, {'id': '251', 'type': 'try_statement', 'children': ['252', '257']}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '257', 'type': 'except_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'try_statement', 'children': ['260', '290']}; {'id': '260', 'type': 'block', 'children': ['261', '277']}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'xw'}; {'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': 'configGet'}; {'id': '270', 'type': 'argument_list', 'children': ['271', '272', '273', '274']}, {'id': '271', 'type': 'string', 'children': [], 'value': "'string'"}; {'id': '272', 'type': 'string', 'children': [], 'value': '"input"'}, {'id': '273', 'type': 'string', 'children': [], 'value': '"xw"'}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'optional'}; {'id': '276', 'type': 'True', 'children': []}, {'id': '277', 'type': 'if_statement', 'children': ['278', '283']}; {'id': '278', 'type': 'comparison_operator', 'children': ['279', '282'], 'value': '=='}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'xw'}; {'id': '282', 'type': 'string', 'children': [], 'value': "''"}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '289', 'type': 'None', 'children': []}; {'id': '290', 'type': 'except_clause', 'children': ['291']}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '297', 'type': 'None', 'children': []}; {'id': '298', 'type': 'if_statement', 'children': ['299', '307']}, {'id': '299', 'type': 'comparison_operator', 'children': ['300', '306'], 'value': '=='}; {'id': '300', 'type': 'call', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'xw'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'loadFile'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '321', 'type': 'if_statement', 'children': ['322', '327']}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '326'], 'value': '=='}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'dimension'}; {'id': '326', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '327', 'type': 'block', 'children': ['328', '375', '410']}; {'id': '328', 'type': 'try_statement', 'children': ['329', '334']}, {'id': '329', 'type': 'block', 'children': ['330']}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '334', 'type': 'except_clause', 'children': ['335']}, {'id': '335', 'type': 'block', 'children': ['336']}; {'id': '336', 'type': 'try_statement', 'children': ['337', '367']}, {'id': '337', 'type': 'block', 'children': ['338', '354']}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}, {'id': '339', 'type': 'assignment', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'configGet'}, {'id': '347', 'type': 'argument_list', 'children': ['348', '349', '350', '351']}; {'id': '348', 'type': 'string', 'children': [], 'value': "'string'"}, {'id': '349', 'type': 'string', 'children': [], 'value': '"input"'}; {'id': '350', 'type': 'string', 'children': [], 'value': '"yw"'}, {'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'optional'}, {'id': '353', 'type': 'True', 'children': []}; {'id': '354', 'type': 'if_statement', 'children': ['355', '360']}, {'id': '355', 'type': 'comparison_operator', 'children': ['356', '359'], 'value': '=='}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '359', 'type': 'string', 'children': [], 'value': "''"}; {'id': '360', 'type': 'block', 'children': ['361']}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '366', 'type': 'None', 'children': []}, {'id': '367', 'type': 'except_clause', 'children': ['368']}; {'id': '368', 'type': 'block', 'children': ['369']}, {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'assignment', 'children': ['371', '374']}, {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '374', 'type': 'None', 'children': []}, {'id': '375', 'type': 'if_statement', 'children': ['376', '402']}; {'id': '376', 'type': 'boolean_operator', 'children': ['377', '389', '390'], 'value': 'or'}, {'id': '377', 'type': 'parenthesized_expression', 'children': ['378'], 'value': '()'}; {'id': '378', 'type': 'boolean_operator', 'children': ['379', '384'], 'value': 'and'}, {'id': '379', 'type': 'comparison_operator', 'children': ['380', '383'], 'value': 'is'}; {'id': '380', 'type': 'attribute', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '383', 'type': 'None', 'children': []}; {'id': '384', 'type': 'comparison_operator', 'children': ['385', '388'], 'value': 'is'}, {'id': '385', 'type': 'attribute', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '388', 'type': 'None', 'children': []}, {'id': '389', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '390', 'type': 'parenthesized_expression', 'children': ['391'], 'value': '()'}, {'id': '391', 'type': 'boolean_operator', 'children': ['392', '397'], 'value': 'and'}; {'id': '392', 'type': 'comparison_operator', 'children': ['393', '396'], 'value': 'is'}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'xw'}; {'id': '396', 'type': 'None', 'children': []}, {'id': '397', 'type': 'comparison_operator', 'children': ['398', '401'], 'value': 'is'}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '401', 'type': 'None', 'children': []}; {'id': '402', 'type': 'block', 'children': ['403']}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'call', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'string', 'children': [], 'value': '"SAS_NG output at specified points requires both xw and yw to be defined"'}; {'id': '410', 'type': 'if_statement', 'children': ['411', '419', '433']}, {'id': '411', 'type': 'comparison_operator', 'children': ['412', '418'], 'value': '=='}; {'id': '412', 'type': 'call', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '414', 'type': 'argument_list', 'children': ['415']}, {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '419', 'type': 'block', 'children': ['420']}; {'id': '420', 'type': 'expression_statement', 'children': ['421']}, {'id': '421', 'type': 'assignment', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '425', 'type': 'call', 'children': ['426', '429']}; {'id': '426', 'type': 'attribute', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'loadFile'}, {'id': '429', 'type': 'argument_list', 'children': ['430']}; {'id': '430', 'type': 'attribute', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '433', 'type': 'elif_clause', 'children': ['434', '439']}; {'id': '434', 'type': 'comparison_operator', 'children': ['435', '438'], 'value': 'is'}, {'id': '435', 'type': 'attribute', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'yw'}; {'id': '438', 'type': 'None', 'children': []}, {'id': '439', 'type': 'block', 'children': ['440']}; {'id': '440', 'type': 'expression_statement', 'children': ['441']}, {'id': '441', 'type': 'assignment', 'children': ['442', '445']}; {'id': '442', 'type': 'attribute', 'children': ['443', '444']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'yw'}, {'id': '445', 'type': 'call', 'children': ['446', '451']}; {'id': '446', 'type': 'attribute', 'children': ['447', '450']}, {'id': '447', 'type': 'attribute', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '451', 'type': 'argument_list', 'children': []}; {'id': '452', 'type': 'if_statement', 'children': ['453', '458']}, {'id': '453', 'type': 'comparison_operator', 'children': ['454', '457'], 'value': 'is'}; {'id': '454', 'type': 'attribute', 'children': ['455', '456']}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'xw'}, {'id': '457', 'type': 'None', 'children': []}; {'id': '458', 'type': 'block', 'children': ['459']}, {'id': '459', 'type': 'expression_statement', 'children': ['460']}; {'id': '460', 'type': 'assignment', 'children': ['461', '464']}, {'id': '461', 'type': 'attribute', 'children': ['462', '463']}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '463', 'type': 'identifier', 'children': [], 'value': 'xw'}; {'id': '464', 'type': 'call', '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': 'x'}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'copy'} | def SAS_NG(self):
if self.filename:
self.Te = self.configGet("float", "input", "ElasticThickness")
self.latlon = self.configGet("string", "numerical2D", "latlon", optional=True)
self.PlanetaryRadius = self.configGet("float", "numerical2D", "PlanetaryRadius", optional=True)
if self.dimension == 2:
from scipy.special import kei
if self.dimension == 1:
try:
self.x
self.q
except:
if self.q0.shape[1] == 2:
self.x = self.q0[:,0]
self.q = self.q0[:,1]
else:
sys.exit("For 1D (ungridded) SAS_NG configuration file, need [x,w] array. Your dimensions are: "+str(self.q0.shape))
else:
try:
self.x
self.u
self.q
except:
if self.q0.shape[1] == 3:
self.x = self.q0[:,0]
self.y = self.q0[:,1]
self.q = self.q0[:,2]
else:
sys.exit("For 2D (ungridded) SAS_NG configuration file, need [x,y,w] array. Your dimensions are: "+str(self.q0.shape))
self.x = self.x
if self.dimension == 2:
self.y = self.y
del self.q0
try:
self.xw
except:
try:
self.xw = self.configGet('string', "input", "xw", optional=True)
if self.xw == '':
self.xw = None
except:
self.xw = None
if type(self.xw) == str:
self.xw = self.loadFile(self.xw)
if self.dimension == 2:
try:
self.yw
except:
try:
self.yw = self.configGet('string', "input", "yw", optional=True )
if self.yw == '':
self.yw = None
except:
self.yw = None
if (self.xw is not None and self.yw is None) \
or (self.xw is None and self.yw is not None):
sys.exit("SAS_NG output at specified points requires both xw and yw to be defined")
if type(self.yw) == str:
self.yw = self.loadFile(self.yw)
elif self.yw is None:
self.yw = self.y.copy()
if self.xw is None:
self.xw = self.x.copy() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_c3_mro'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '48', '58', '71', '75', '88', '121', '132', '146', '160', '174']}, {'id': '9', 'type': 'for_statement', 'children': ['10', '13', '22', '42']}; {'id': '10', 'type': 'pattern_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'__abstractmethods__'"}, {'id': '29', 'type': 'block', 'children': ['30', '41']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'boundary'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '40'], 'value': '-'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'break_statement', 'children': []}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'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': 'boundary'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '51', 'type': 'conditional_expression', 'children': ['52', '56', '57'], 'value': 'if'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'abcs'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'explicit_bases'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '68', 'type': 'slice', 'children': ['69', '70']}, {'id': '69', 'type': 'colon', 'children': []}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'boundary'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'abstract_bases'}; {'id': '74', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'other_bases'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'subscript', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '__bases__'}, {'id': '85', 'type': 'slice', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'boundary'}, {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '113']}, {'id': '93', 'type': 'boolean_operator', 'children': ['94', '99'], 'value': 'and'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '102', 'type': 'generator_expression', 'children': ['103', '108']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'issubclass'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '__bases__'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'abstract_bases'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'abstract_bases'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'explicit_c3_mros'}, {'id': '135', 'type': 'list_comprehension', 'children': ['136', '143']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_c3_mro'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'abcs'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '143', 'type': 'for_in_clause', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'explicit_bases'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'abstract_c3_mros'}, {'id': '149', 'type': 'list_comprehension', 'children': ['150', '157']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': '_c3_mro'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'abcs'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'abstract_bases'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'other_c3_mros'}, {'id': '163', 'type': 'list_comprehension', 'children': ['164', '171']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': '_c3_mro'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'abcs'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'abcs'}, {'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'other_bases'}; {'id': '174', 'type': 'return_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': '_c3_merge'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '194'], 'value': '+'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '192'], 'value': '+'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '190'], 'value': '+'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '189'], 'value': '+'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '188'], 'value': '+'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '+'}; {'id': '184', 'type': 'list', 'children': ['185'], 'value': '[[cls]]'}, {'id': '185', 'type': 'list', 'children': ['186'], 'value': '[cls]'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'explicit_c3_mros'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'abstract_c3_mros'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'other_c3_mros'}; {'id': '190', 'type': 'list', 'children': ['191'], 'value': '[explicit_bases]'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'explicit_bases'}; {'id': '192', 'type': 'list', 'children': ['193'], 'value': '[abstract_bases]'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'abstract_bases'}; {'id': '194', 'type': 'list', 'children': ['195'], 'value': '[\n other_bases]'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'other_bases'} | def _c3_mro(cls, abcs=None):
for i, base in enumerate(reversed(cls.__bases__)):
if hasattr(base, '__abstractmethods__'):
boundary = len(cls.__bases__) - i
break
else:
boundary = 0
abcs = list(abcs) if abcs else []
explicit_bases = list(cls.__bases__[:boundary])
abstract_bases = []
other_bases = list(cls.__bases__[boundary:])
for base in abcs:
if issubclass(cls, base) and not any(issubclass(b, base) for b in cls.__bases__):
abstract_bases.append(base)
for base in abstract_bases:
abcs.remove(base)
explicit_c3_mros = [_c3_mro(base, abcs=abcs) for base in explicit_bases]
abstract_c3_mros = [_c3_mro(base, abcs=abcs) for base in abstract_bases]
other_c3_mros = [_c3_mro(base, abcs=abcs) for base in other_bases]
return _c3_merge(
[[cls]] + explicit_c3_mros + abstract_c3_mros + other_c3_mros + [explicit_bases] + [abstract_bases] + [
other_bases]) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'singledispatch'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'function'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '16', '21', '27', '102', '159', '182', '188', '194', '200', '209', '217', '223']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'registry'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dispatch_cache'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'WeakKeyDictionary'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'function_definition', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'function_name', 'children': [], 'value': 'ns'}; {'id': '18', 'type': 'parameters', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'pass_statement', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cache_token'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'function_definition', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'function_name', 'children': [], 'value': 'dispatch'}, {'id': '29', 'type': 'parameters', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '31', 'type': 'block', 'children': ['32', '64', '100']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': 'is'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cache_token'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39', '45']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_cache_token'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'if_statement', 'children': ['46', '51']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '!='}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cache_token'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'current_token'}, {'id': '51', 'type': 'block', 'children': ['52', '58']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dispatch_cache'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'clear'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cache_token'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'current_token'}; {'id': '64', 'type': 'try_statement', 'children': ['65', '72']}, {'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': 'impl'}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dispatch_cache'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '72', 'type': 'except_clause', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '74', 'type': 'block', 'children': ['75', '94']}, {'id': '75', 'type': 'try_statement', 'children': ['76', '83']}; {'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': 'impl'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'registry'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '83', 'type': 'except_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'impl'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_find_impl'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'registry'}; {'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': 'dispatch_cache'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'impl'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'impl'}; {'id': '102', 'type': 'function_definition', 'children': ['103', '104', '109']}, {'id': '103', 'type': 'function_name', 'children': [], 'value': 'register'}; {'id': '104', 'type': 'parameters', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '106', 'type': 'default_parameter', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'block', 'children': ['110', '124', '130', '151', '157']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '114']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'lambda', 'children': ['117', '119']}, {'id': '117', 'type': 'lambda_parameters', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'register'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'registry'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '130', 'type': 'if_statement', 'children': ['131', '142']}, {'id': '131', 'type': 'boolean_operator', 'children': ['132', '137'], 'value': 'and'}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': 'is'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'cache_token'}; {'id': '136', 'type': 'None', 'children': []}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'__abstractmethods__'"}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ns'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cache_token'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_cache_token'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'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': 'dispatch_cache'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'clear'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '159', 'type': 'function_definition', 'children': ['160', '161', '166']}; {'id': '160', 'type': 'function_name', 'children': [], 'value': 'wrapper'}, {'id': '161', 'type': 'parameters', 'children': ['162', '164']}; {'id': '162', 'type': 'list_splat_pattern', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '164', 'type': 'dictionary_splat_pattern', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '177']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'dispatch'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '180']}; {'id': '178', 'type': 'list_splat', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '180', 'type': 'dictionary_splat', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'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': 'registry'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'object'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'register'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'dispatch'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dispatch'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'registry'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'MappingProxyType'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'registry'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'wrapper'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': '_clear_cache'}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'dispatch_cache'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'clear'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'update_wrapper'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'function'}, {'id': '223', 'type': 'return_statement', 'children': ['224']} | def singledispatch(function):
registry = {}
dispatch_cache = WeakKeyDictionary()
def ns():
pass
ns.cache_token = None
def dispatch(cls):
if ns.cache_token is not None:
current_token = get_cache_token()
if ns.cache_token != current_token:
dispatch_cache.clear()
ns.cache_token = current_token
try:
impl = dispatch_cache[cls]
except KeyError:
try:
impl = registry[cls]
except KeyError:
impl = _find_impl(cls, registry)
dispatch_cache[cls] = impl
return impl
def register(cls, func=None):
if func is None:
return lambda f: register(cls, f)
registry[cls] = func
if ns.cache_token is None and hasattr(cls, '__abstractmethods__'):
ns.cache_token = get_cache_token()
dispatch_cache.clear()
return func
def wrapper(*args, **kw):
return dispatch(args[0].__class__)(*args, **kw)
registry[object] = function
wrapper.register = register
wrapper.dispatch = dispatch
wrapper.registry = MappingProxyType(registry)
wrapper._clear_cache = dispatch_cache.clear
update_wrapper(wrapper, function)
return wrapper |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '40']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'createResource'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'resource_type'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'resource_file'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'resource_filename'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'abstract'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'edit_users'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'view_users'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'edit_groups'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'view_groups'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'extra_metadata'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'progress_callback'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '54', '58', '87', '97', '106', '135', '144', '153', '162', '171', '180', '189', '203', '210', '219', '227', '248', '265', '299', '307', '313']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"{url_base}/resource/"'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'url_base'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'url_base'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'close_fd'}, {'id': '57', 'type': 'False', 'children': []}; {'id': '58', 'type': 'if_statement', 'children': ['59', '64']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'not'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'resource_type'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'resource_types'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'HydroShareArgumentException'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': '"Resource type {0} is not among known resources: {1}"'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'resource_type'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'list_comprehension', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'resource_types'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '90', 'type': 'dictionary', 'children': ['91', '94']}, {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'resource_type'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'resource_type'}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'abstract'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'abstract'"}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'for_statement', 'children': ['110', '113', '117']}; {'id': '110', 'type': 'tuple_pattern', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'keywords'}, {'id': '117', 'type': 'block', 'children': ['118', '129']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': '"keywords[{index}]"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'edit_users'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'edit_users'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'edit_users'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'view_users'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'view_users'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'view_users'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'edit_groups'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'edit_groups'"}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'edit_groups'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'view_groups'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '170']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '169', 'type': 'string', 'children': [], 'value': "'view_groups'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'view_groups'}, {'id': '171', 'type': 'if_statement', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'metadata'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'metadata'"}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '180', 'type': 'if_statement', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'extra_metadata'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'extra_metadata'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'extra_metadata'}, {'id': '189', 'type': 'if_statement', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'resource_file'}, {'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': 'close_fd'}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_prepareFileForUpload'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201', '202']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'resource_file'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'resource_filename'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'encoder'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'MultipartEncoder'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '214']}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'is'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'progress_callback'}, {'id': '213', 'type': 'None', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'progress_callback'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'default_progress_callback'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'monitor'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'MultipartEncoderMonitor'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'encoder'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'progress_callback'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '_request'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '240']}, {'id': '235', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'monitor'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '242', 'type': 'dictionary', 'children': ['243']}, {'id': '243', 'type': 'pair', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'Content-Type'"}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'monitor'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '248', 'type': 'if_statement', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'close_fd'}; {'id': '250', 'type': 'block', 'children': ['251', '259']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '254', 'type': 'subscript', 'children': ['255', '258']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'file'"}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '264', 'type': 'argument_list', 'children': []}, {'id': '265', 'type': 'if_statement', 'children': ['266', '271']}; {'id': '266', 'type': 'comparison_operator', 'children': ['267', '270'], 'value': '!='}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '201'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'if_statement', 'children': ['273', '278', '286']}, {'id': '273', 'type': 'comparison_operator', 'children': ['274', '277'], 'value': '=='}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '403'}; {'id': '278', 'type': 'block', 'children': ['279']}, {'id': '279', 'type': 'raise_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'HydroShareNotAuthorized'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'tuple', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '286', 'type': 'else_clause', 'children': ['287']}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'raise_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'HydroShareHTTPException'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'tuple', 'children': ['293', '294', '295', '298']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '306', 'type': 'argument_list', 'children': []}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'new_resource_id'}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'resource_id'"}, {'id': '313', 'type': 'return_statement', 'children': ['314']} | def createResource(self, resource_type, title, resource_file=None, resource_filename=None,
abstract=None, keywords=None,
edit_users=None, view_users=None, edit_groups=None, view_groups=None,
metadata=None, extra_metadata=None, progress_callback=None):
url = "{url_base}/resource/".format(url_base=self.url_base)
close_fd = False
if resource_type not in self.resource_types:
raise HydroShareArgumentException("Resource type {0} is not among known resources: {1}".format(resource_type,
", ".join([r for r in self.resource_types])))
params = {'resource_type': resource_type, 'title': title}
if abstract:
params['abstract'] = abstract
if keywords:
for (i, kw) in enumerate(keywords):
key = "keywords[{index}]".format(index=i)
params[key] = kw
if edit_users:
params['edit_users'] = edit_users
if view_users:
params['view_users'] = view_users
if edit_groups:
params['edit_groups'] = edit_groups
if view_groups:
params['view_groups'] = view_groups
if metadata:
params['metadata'] = metadata
if extra_metadata:
params['extra_metadata'] = extra_metadata
if resource_file:
close_fd = self._prepareFileForUpload(params, resource_file, resource_filename)
encoder = MultipartEncoder(params)
if progress_callback is None:
progress_callback = default_progress_callback
monitor = MultipartEncoderMonitor(encoder, progress_callback)
r = self._request('POST', url, data=monitor, headers={'Content-Type': monitor.content_type})
if close_fd:
fd = params['file'][1]
fd.close()
if r.status_code != 201:
if r.status_code == 403:
raise HydroShareNotAuthorized(('POST', url))
else:
raise HydroShareHTTPException((url, 'POST', r.status_code, params))
response = r.json()
new_resource_id = response['resource_id']
return new_resource_id |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getResourceFile'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '30', '76', '89', '136']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"{url_base}/resource/{pid}/files/{filename}"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '24', '27']}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'url_base'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'url_base'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '32', 'type': 'block', 'children': ['33', '54']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '43']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'HydroShareArgumentException'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"{0} is not a directory."'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '65']}, {'id': '55', 'type': 'not_operator', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'access'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'W_OK'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'raise_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'HydroShareArgumentException'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"You do not have write permissions to directory \'{0}\'."'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'destination'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_request'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '88', 'type': 'True', 'children': []}, {'id': '89', 'type': 'if_statement', 'children': ['90', '95']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '!='}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '200'}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '102', '110', '124']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '=='}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '403'}; {'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': 'HydroShareNotAuthorized'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'tuple', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '110', 'type': 'elif_clause', 'children': ['111', '116']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '=='}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '404'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'raise_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'HydroShareNotFound'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'tuple', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '124', 'type': 'else_clause', 'children': ['125']}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'raise_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'HydroShareHTTPException'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'tuple', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140', '148']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '139', 'type': 'None', 'children': []}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'iter_content'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'STREAM_CHUNK_SIZE'}; {'id': '148', 'type': 'else_clause', 'children': ['149']}, {'id': '149', 'type': 'block', 'children': ['150', '162', '190']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'destination'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '162', 'type': 'with_statement', 'children': ['163', '173']}, {'id': '163', 'type': 'with_clause', 'children': ['164']}; {'id': '164', 'type': 'with_item', 'children': ['165']}, {'id': '165', 'type': 'as_pattern', 'children': ['166', '171']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'wb'"}, {'id': '171', 'type': 'as_pattern_target', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '182']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'iter_content'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'STREAM_CHUNK_SIZE'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '190', 'type': 'return_statement', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'filepath'} | def getResourceFile(self, pid, filename, destination=None):
url = "{url_base}/resource/{pid}/files/{filename}".format(url_base=self.url_base,
pid=pid,
filename=filename)
if destination:
if not os.path.isdir(destination):
raise HydroShareArgumentException("{0} is not a directory.".format(destination))
if not os.access(destination, os.W_OK):
raise HydroShareArgumentException("You do not have write permissions to directory '{0}'.".format(destination))
r = self._request('GET', url, stream=True)
if r.status_code != 200:
if r.status_code == 403:
raise HydroShareNotAuthorized(('GET', url))
elif r.status_code == 404:
raise HydroShareNotFound((pid, filename))
else:
raise HydroShareHTTPException((url, 'GET', r.status_code))
if destination is None:
return r.iter_content(STREAM_CHUNK_SIZE)
else:
filepath = os.path.join(destination, filename)
with open(filepath, 'wb') as fd:
for chunk in r.iter_content(STREAM_CHUNK_SIZE):
fd.write(chunk)
return filepath |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'upsert'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '16', '29', '449']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'required_parameters'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_stackParameters'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'try_statement', 'children': ['17', '24']}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_initialize_upsert'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'except_clause', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'try_statement', 'children': ['30', '414']}; {'id': '30', 'type': 'block', 'children': ['31', '41', '63', '75', '87', '91', '155', '170', '221', '243', '261']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'available_parameters'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_parameters'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '52']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}, {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_template'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'Parameters'"}, {'id': '51', 'type': 'dictionary', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'required_parameters'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parameter_name'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'}; {'id': '70', 'type': 'string', 'children': [], 'value': "' required parameters: '"}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'required_parameters'}, {'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': 'logging'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'available parameters: '"}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'available_parameters'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '90', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'required_parameters'}; {'id': '94', 'type': 'block', 'children': ['95', '99', '108', '115', '148']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '98', 'type': 'dictionary', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'ParameterKey'"}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '121', '132']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_parameters'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'ParameterValue'"}, {'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': '_parameters'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'ParameterValue'"}, {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_parameters'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'required_parameter'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '162']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_analyze_stuff'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'block', 'children': ['163']}, {'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': 'sys'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '180']}, {'id': '171', 'type': 'call', 'children': ['172', '177']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_config'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'dryrun'"}, {'id': '179', 'type': 'False', 'children': []}; {'id': '180', 'type': 'block', 'children': ['181', '188', '197', '207', '214']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'string', 'children': [], 'value': "'Generating change set'"}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'set_id'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': '_generate_change_set'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'set_id'}, {'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': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': '_describe_change_set'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'set_id'}, {'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': 'logging'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'string', 'children': [], 'value': "'This was a dryrun'"}; {'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': 'sys'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'integer', 'children': [], 'value': '0'}, {'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': '_tags'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'dictionary', 'children': ['230', '233']}; {'id': '230', 'type': 'pair', 'children': ['231', '232']}, {'id': '231', 'type': 'string', 'children': [], 'value': '"Key"'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"CODE_VERSION_SD"'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': '"Value"'}, {'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': '_config'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'codeVersion'"}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '250']}, {'id': '245', 'type': 'attribute', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '_tags'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'dictionary', 'children': ['252', '255']}; {'id': '252', 'type': 'pair', 'children': ['253', '254']}, {'id': '253', 'type': 'string', 'children': [], 'value': '"Key"'}; {'id': '254', 'type': 'string', 'children': [], 'value': '"ANSWER"'}, {'id': '255', 'type': 'pair', 'children': ['256', '257']}; {'id': '256', 'type': 'string', 'children': [], 'value': '"Value"'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'integer', 'children': [], 'value': '42'}, {'id': '261', 'type': 'if_statement', 'children': ['262', '265', '339']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': '_updateStack'}, {'id': '265', 'type': 'block', 'children': ['266', '321']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '269', 'type': 'call', 'children': ['270', '275']}; {'id': '270', 'type': 'attribute', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': '_cloudFormation'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'update_stack'}, {'id': '275', 'type': 'argument_list', 'children': ['276', '293', '298', '301', '306', '311']}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'StackName'}; {'id': '278', 'type': 'call', 'children': ['279', '290']}, {'id': '279', 'type': 'attribute', 'children': ['280', '289']}; {'id': '280', 'type': 'call', 'children': ['281', '286']}, {'id': '281', 'type': 'attribute', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': '_config'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'environment'"}; {'id': '288', 'type': 'dictionary', 'children': []}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '292']}, {'id': '291', 'type': 'string', 'children': [], 'value': "'stack_name'"}; {'id': '292', 'type': 'None', 'children': []}, {'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'TemplateURL'}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': '_templateUrl'}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'Capabilities'}, {'id': '303', 'type': 'list', 'children': ['304', '305'], 'value': "['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']"}; {'id': '304', 'type': 'string', 'children': [], 'value': "'CAPABILITY_IAM'"}, {'id': '305', 'type': 'string', 'children': [], 'value': "'CAPABILITY_NAMED_IAM'"}; {'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'Tags'}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': '_tags'}, {'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'ClientRequestToken'}, {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'uuid4'}; {'id': '320', 'type': 'argument_list', 'children': []}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'call', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '326', 'type': 'argument_list', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'string', 'children': [], 'value': "'existing stack ID: {}'"}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'format'}, {'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': 'stack'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '338']}, {'id': '337', 'type': 'string', 'children': [], 'value': "'StackId'"}; {'id': '338', 'type': 'string', 'children': [], 'value': "'unknown'"}, {'id': '339', 'type': 'else_clause', 'children': ['340']}; {'id': '340', 'type': 'block', 'children': ['341', '396']}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'assignment', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '344', 'type': 'call', 'children': ['345', '350']}, {'id': '345', 'type': 'attribute', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': '_cloudFormation'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'create_stack'}; {'id': '350', 'type': 'argument_list', 'children': ['351', '368', '373', '376', '381', '386']}, {'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'StackName'}, {'id': '353', 'type': 'call', 'children': ['354', '365']}; {'id': '354', 'type': 'attribute', 'children': ['355', '364']}, {'id': '355', 'type': 'call', 'children': ['356', '361']}; {'id': '356', 'type': 'attribute', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': '_config'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '361', 'type': 'argument_list', 'children': ['362', '363']}; {'id': '362', 'type': 'string', 'children': [], 'value': "'environment'"}, {'id': '363', 'type': 'dictionary', 'children': []}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '365', 'type': 'argument_list', 'children': ['366', '367']}; {'id': '366', 'type': 'string', 'children': [], 'value': "'stack_name'"}, {'id': '367', 'type': 'None', 'children': []}; {'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'TemplateURL'}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': '_templateUrl'}, {'id': '373', 'type': 'keyword_argument', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '376', 'type': 'keyword_argument', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'Capabilities'}; {'id': '378', 'type': 'list', 'children': ['379', '380'], 'value': "['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']"}, {'id': '379', 'type': 'string', 'children': [], 'value': "'CAPABILITY_IAM'"}; {'id': '380', 'type': 'string', 'children': [], 'value': "'CAPABILITY_NAMED_IAM'"}, {'id': '381', 'type': 'keyword_argument', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'Tags'}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': '_tags'}; {'id': '386', 'type': 'keyword_argument', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'ClientRequestToken'}; {'id': '388', 'type': 'call', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '390', 'type': 'argument_list', 'children': ['391']}, {'id': '391', 'type': 'call', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'uuid4'}, {'id': '395', 'type': 'argument_list', 'children': []}; {'id': '396', 'type': 'expression_statement', 'children': ['397']}, {'id': '397', 'type': 'call', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '401', 'type': 'argument_list', 'children': ['402']}; {'id': '402', 'type': 'call', 'children': ['403', '406']}, {'id': '403', 'type': 'attribute', 'children': ['404', '405']}; {'id': '404', 'type': 'string', 'children': [], 'value': "'new stack ID: {}'"}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '406', 'type': 'argument_list', 'children': ['407']}, {'id': '407', 'type': 'call', 'children': ['408', '411']}; {'id': '408', 'type': 'attribute', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '411', 'type': 'argument_list', 'children': ['412', '413']}; {'id': '412', 'type': 'string', 'children': [], 'value': "'StackId'"}, {'id': '413', 'type': 'string', 'children': [], 'value': "'unknown'"}; {'id': '414', 'type': 'except_clause', 'children': ['415', '419']}, {'id': '415', 'type': 'as_pattern', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '417', 'type': 'as_pattern_target', 'children': ['418']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '419', 'type': 'block', 'children': ['420', '447']}; {'id': '420', 'type': 'if_statement', 'children': ['421', '424', '435']}, {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': '_verbose'}; {'id': '424', 'type': 'block', 'children': ['425']}, {'id': '425', 'type': 'expression_statement', 'children': ['426']}; {'id': '426', 'type': 'call', 'children': ['427', '430']}, {'id': '427', 'type': 'attribute', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '430', 'type': 'argument_list', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '432', 'type': 'keyword_argument', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'exc_info'}; {'id': '434', 'type': 'True', 'children': []}, {'id': '435', 'type': 'else_clause', 'children': ['436']}; {'id': '436', 'type': 'block', 'children': ['437']}, {'id': '437', 'type': 'expression_statement', 'children': ['438']}; {'id': '438', 'type': 'call', 'children': ['439', '442']}, {'id': '439', 'type': 'attribute', 'children': ['440', '441']}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '441', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '442', 'type': 'argument_list', 'children': ['443', '444']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '444', 'type': 'keyword_argument', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'exc_info'}; {'id': '446', 'type': 'False', 'children': []}, {'id': '447', 'type': 'return_statement', 'children': ['448']}; {'id': '448', 'type': 'False', 'children': []}, {'id': '449', 'type': 'return_statement', 'children': ['450']} | def upsert(self):
required_parameters = []
self._stackParameters = []
try:
self._initialize_upsert()
except Exception:
return False
try:
available_parameters = self._parameters.keys()
for parameter_name in self._template.get('Parameters', {}):
required_parameters.append(str(parameter_name))
logging.info(' required parameters: ' + str(required_parameters))
logging.info('available parameters: ' + str(available_parameters))
parameters = []
for required_parameter in required_parameters:
parameter = {}
parameter['ParameterKey'] = str(required_parameter)
required_parameter = str(required_parameter)
if required_parameter in self._parameters:
parameter['ParameterValue'] = self._parameters[required_parameter]
else:
parameter['ParameterValue'] = self._parameters[required_parameter.lower()]
parameters.append(parameter)
if not self._analyze_stuff():
sys.exit(1)
if self._config.get('dryrun', False):
logging.info('Generating change set')
set_id = self._generate_change_set(parameters)
if set_id:
self._describe_change_set(set_id)
logging.info('This was a dryrun')
sys.exit(0)
self._tags.append({"Key": "CODE_VERSION_SD", "Value": self._config.get('codeVersion')})
self._tags.append({"Key": "ANSWER", "Value": str(42)})
if self._updateStack:
stack = self._cloudFormation.update_stack(
StackName=self._config.get('environment', {}).get('stack_name', None),
TemplateURL=self._templateUrl,
Parameters=parameters,
Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
Tags=self._tags,
ClientRequestToken=str(uuid.uuid4())
)
logging.info('existing stack ID: {}'.format(stack.get('StackId', 'unknown')))
else:
stack = self._cloudFormation.create_stack(
StackName=self._config.get('environment', {}).get('stack_name', None),
TemplateURL=self._templateUrl,
Parameters=parameters,
Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
Tags=self._tags,
ClientRequestToken=str(uuid.uuid4())
)
logging.info('new stack ID: {}'.format(stack.get('StackId', 'unknown')))
except Exception as x:
if self._verbose:
logging.error(x, exc_info=True)
else:
logging.error(x, exc_info=False)
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '19', '50']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '19', 'type': 'block', 'children': ['20', '39']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '23', 'type': 'call', 'children': ['24', '37']}; {'id': '24', 'type': 'attribute', 'children': ['25', '36']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'YAMLEncoder'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '31', '34']}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '34', 'type': 'dictionary_splat', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'iterencode'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '50', 'type': 'else_clause', 'children': ['51']}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57', '60', '63']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '63', 'type': 'dictionary_splat', 'children': ['64']} | def dump(obj, fp=None, indent=None, sort_keys=False, **kw):
if fp:
iterable = YAMLEncoder(indent=indent, sort_keys=sort_keys, **kw).iterencode(obj)
for chunk in iterable:
fp.write(chunk)
else:
return dumps(obj, indent=indent, sort_keys=sort_keys, **kw) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_reference'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '19', '29', '39', '49', '316']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'reference'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'bibliographyLink'"}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'raise_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'MissingElementError'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'bibliographyLink'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ref_doi'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'doi'"}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ref_key'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'preferredKey'"}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53', '274', '308']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ref_doi'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'try_statement', 'children': ['55', '69', '118']}, {'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': 'ref'}, {'id': '59', 'type': 'subscript', 'children': ['60', '68']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'crossref_api'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'works'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ids'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ref_doi'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'message'"}, {'id': '69', 'type': 'except_clause', 'children': ['70', '76']}; {'id': '70', 'type': 'tuple', 'children': ['71', '72', '75']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'HTTPError'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'habanero'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'RequestError'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81', '87']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ref_key'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'KeywordError'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'DOI not found and preferredKey attribute not set'"}, {'id': '87', 'type': 'else_clause', 'children': ['88']}; {'id': '88', 'type': 'block', 'children': ['89', '96', '102']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'Missing doi attribute in bibliographyLink or lookup failed. '"}, {'id': '95', 'type': 'string', 'children': [], 'value': '\'Setting "detail" key as a fallback; please update to the appropriate fields.\''}; {'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': 'reference'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'detail'"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ref_key'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '111']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '110'], 'value': '!='}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'reference'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'detail'"}; {'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'augmented_assignment', 'children': ['114', '117'], 'value': '+='}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'detail'"}, {'id': '117', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '118', 'type': 'else_clause', 'children': ['119']}, {'id': '119', 'type': 'block', 'children': ['120', '130', '140', '153', '169', '184', '198', '209', '215']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ref_key'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'Using DOI to obtain reference information, rather than preferredKey.'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'doi'"}, {'id': '135', 'type': 'subscript', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'attrib'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'doi'"}; {'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': 'reference'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'journal'"}, {'id': '145', 'type': 'subscript', 'children': ['146', '152']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'container-title'"}; {'id': '152', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ref_year'}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '163'], 'value': 'or'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'published-print'"}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'published-online'"}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'reference'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'year'"}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'subscript', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ref_year'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'date-parts'"}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '189']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'volume'"}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'string', 'children': [], 'value': "'volume'"}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'pages'"}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'page'"}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'reference'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'authors'"}; {'id': '214', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '215', 'type': 'for_statement', 'children': ['216', '217', '220']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'author'}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '219', 'type': 'string', 'children': [], 'value': "'author'"}; {'id': '220', 'type': 'block', 'children': ['221', '225', '242', '251', '265']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '224', 'type': 'dictionary', 'children': []}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '230']}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '229', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'list', 'children': ['236', '239'], 'value': "[author['given'], author['family']]"}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '238', 'type': 'string', 'children': [], 'value': "'given'"}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'author'}, {'id': '241', 'type': 'string', 'children': [], 'value': "'family'"}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'orcid'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'ORCID'"}, {'id': '251', 'type': 'if_statement', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'orcid'}, {'id': '253', 'type': 'block', 'children': ['254']}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '259']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'ORCID'"}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'orcid'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'string', 'children': [], 'value': "'http://orcid.org/'"}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '272']}, {'id': '267', 'type': 'attribute', 'children': ['268', '271']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'authors'"}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'auth'}; {'id': '274', 'type': 'elif_clause', 'children': ['275', '278']}, {'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': 'is'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ref_key'}, {'id': '277', 'type': 'None', 'children': []}; {'id': '278', 'type': 'block', 'children': ['279', '286', '292']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'concatenated_string', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'Missing doi attribute in bibliographyLink. '"}, {'id': '285', 'type': 'string', 'children': [], 'value': '\'Setting "detail" key as a fallback; please update to the appropriate fields.\''}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'detail'"}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ref_key'}; {'id': '292', 'type': 'if_statement', 'children': ['293', '301']}, {'id': '293', 'type': 'comparison_operator', 'children': ['294', '300'], 'value': '!='}; {'id': '294', 'type': 'subscript', 'children': ['295', '298']}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'reference'}, {'id': '297', 'type': 'string', 'children': [], 'value': "'detail'"}; {'id': '298', 'type': 'unary_operator', 'children': ['299'], 'value': '-'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'augmented_assignment', 'children': ['304', '307'], 'value': '+='}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'reference'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'detail'"}, {'id': '307', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '308', 'type': 'else_clause', 'children': ['309']}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'raise_statement', 'children': ['311']}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'MissingAttributeError'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '315']}; {'id': '314', 'type': 'string', 'children': [], 'value': "'preferredKey'"}, {'id': '315', 'type': 'string', 'children': [], 'value': "'bibliographyLink'"}; {'id': '316', 'type': 'return_statement', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'reference'} | def get_reference(root):
reference = {}
elem = root.find('bibliographyLink')
if elem is None:
raise MissingElementError('bibliographyLink')
ref_doi = elem.get('doi', None)
ref_key = elem.get('preferredKey', None)
if ref_doi is not None:
try:
ref = crossref_api.works(ids=ref_doi)['message']
except (HTTPError, habanero.RequestError, ConnectionError):
if ref_key is None:
raise KeywordError('DOI not found and preferredKey attribute not set')
else:
warn('Missing doi attribute in bibliographyLink or lookup failed. '
'Setting "detail" key as a fallback; please update to the appropriate fields.'
)
reference['detail'] = ref_key
if reference['detail'][-1] != '.':
reference['detail'] += '.'
else:
if ref_key is not None:
warn('Using DOI to obtain reference information, rather than preferredKey.')
reference['doi'] = elem.attrib['doi']
reference['journal'] = ref.get('container-title')[0]
ref_year = ref.get('published-print') or ref.get('published-online')
reference['year'] = int(ref_year['date-parts'][0][0])
reference['volume'] = int(ref.get('volume'))
reference['pages'] = ref.get('page')
reference['authors'] = []
for author in ref['author']:
auth = {}
auth['name'] = ' '.join([author['given'], author['family']])
orcid = author.get('ORCID')
if orcid:
auth['ORCID'] = orcid.lstrip('http://orcid.org/')
reference['authors'].append(auth)
elif ref_key is not None:
warn('Missing doi attribute in bibliographyLink. '
'Setting "detail" key as a fallback; please update to the appropriate fields.'
)
reference['detail'] = ref_key
if reference['detail'][-1] != '.':
reference['detail'] += '.'
else:
raise MissingAttributeError('preferredKey', 'bibliographyLink')
return reference |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ReSpecTh_to_ChemKED'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename_xml'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'file_author'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'file_author_orcid'}; {'id': '10', 'type': 'string', 'children': [], 'value': "''"}, {'id': '11', 'type': 'keyword_separator', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '25', '33', '40', '49', '77', '87', '96', '107', '116', '140', '156', '186', '202', '213', '241', '273', '285']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'etree'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'filename_xml'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'getroot'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_file_metadata'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'reference'"}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_reference'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '56']}, {'id': '51', 'type': 'subscript', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'reference'"}, {'id': '55', 'type': 'string', 'children': [], 'value': "'detail'"}; {'id': '56', 'type': 'parenthesized_expression', 'children': ['57'], 'value': '()'}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '69'], 'value': '+'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '68'], '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': 'properties'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'reference'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'detail'"}, {'id': '67', 'type': 'string', 'children': [], 'value': "''"}; {'id': '68', 'type': 'string', 'children': [], 'value': "'Converted from ReSpecTh XML file '"}, {'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': 'basename'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'filename_xml'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_experiment_kind'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'common-properties'"}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_common_properties'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '103']}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'common-properties'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'ignition-type'"}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'get_ignition_type'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'datapoints'"}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_datapoints'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'has_pres_rise'}, {'id': '119', 'type': 'parenthesized_expression', 'children': ['120'], 'value': '()'}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '126'], 'value': 'or'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'in'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'pressure-rise'"}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'common-properties'"}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'list_comprehension', 'children': ['130', '131', '136']}; {'id': '130', 'type': 'True', 'children': []}, {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dp'}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'datapoints'"}; {'id': '136', 'type': 'if_clause', 'children': ['137']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'pressure-rise'"}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'dp'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '150']}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '143'], 'value': 'and'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'has_pres_rise'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '149'], 'value': '=='}; {'id': '144', 'type': 'subscript', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'apparatus'"}; {'id': '148', 'type': 'string', 'children': [], 'value': "'kind'"}, {'id': '149', 'type': 'string', 'children': [], 'value': "'rapid compression machine'"}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'raise_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'KeywordError'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'Pressure rise cannot be defined for RCM.'"}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'has_vol_hist'}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'list_comprehension', 'children': ['163', '171', '176']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '170'], 'value': '=='}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'volume'"}, {'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dp'}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'datapoints'"}; {'id': '176', 'type': 'for_in_clause', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'dp'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': "'time-histories'"}; {'id': '184', 'type': 'list', 'children': ['185'], 'value': '[{}]'}, {'id': '185', 'type': 'dictionary', 'children': []}; {'id': '186', 'type': 'if_statement', 'children': ['187', '196']}, {'id': '187', 'type': 'boolean_operator', 'children': ['188', '189'], 'value': 'and'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'has_vol_hist'}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '195'], 'value': '=='}; {'id': '190', 'type': 'subscript', 'children': ['191', '194']}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'apparatus'"}; {'id': '194', 'type': 'string', 'children': [], 'value': "'kind'"}, {'id': '195', 'type': 'string', 'children': [], 'value': "'shock tube'"}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'raise_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'KeywordError'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'string', 'children': [], 'value': "'Volume history cannot be defined for shock tube.'"}; {'id': '202', 'type': 'if_statement', 'children': ['203', '207']}, {'id': '203', 'type': 'boolean_operator', 'children': ['204', '205'], 'value': 'and'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'file_author_orcid'}, {'id': '205', 'type': 'not_operator', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'file_author'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'raise_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'KeywordError'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'string', 'children': [], 'value': "'If file_author_orcid is specified, file_author must be as well'"}, {'id': '213', 'type': 'if_statement', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'file_author'}, {'id': '215', 'type': 'block', 'children': ['216', '223', '232']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'temp_author'}, {'id': '219', 'type': 'dictionary', 'children': ['220']}; {'id': '220', 'type': 'pair', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'file_author'}, {'id': '223', 'type': 'if_statement', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'file_author_orcid'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'temp_author'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'ORCID'"}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'file_author_orcid'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '239']}; {'id': '234', 'type': 'attribute', 'children': ['235', '238']}, {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '237', 'type': 'string', 'children': [], 'value': "'file-authors'"}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'temp_author'}, {'id': '241', 'type': 'for_statement', 'children': ['242', '243', '252']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '251', 'type': 'string', 'children': [], 'value': "'datapoints'"}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'for_statement', 'children': ['254', '255', '258']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'common-properties'"}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '268']}, {'id': '261', 'type': 'subscript', 'children': ['262', '267']}; {'id': '262', 'type': 'subscript', 'children': ['263', '266']}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '265', 'type': 'string', 'children': [], 'value': "'datapoints'"}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '268', 'type': 'subscript', 'children': ['269', '272']}, {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '271', 'type': 'string', 'children': [], 'value': "'common-properties'"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '273', 'type': 'if_statement', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'chemked'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ChemKED'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'dict_input'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '285', 'type': 'return_statement', 'children': ['286']} | def ReSpecTh_to_ChemKED(filename_xml, file_author='', file_author_orcid='', *, validate=False):
tree = etree.parse(filename_xml)
root = tree.getroot()
properties = get_file_metadata(root)
properties['reference'] = get_reference(root)
properties['reference']['detail'] = (properties['reference'].get('detail', '') +
'Converted from ReSpecTh XML file ' +
os.path.basename(filename_xml)
)
properties.update(get_experiment_kind(root))
properties['common-properties'] = get_common_properties(root)
properties['common-properties']['ignition-type'] = get_ignition_type(root)
properties['datapoints'] = get_datapoints(root)
has_pres_rise = ('pressure-rise' in properties['common-properties'] or
any([True for dp in properties['datapoints'] if 'pressure-rise' in dp])
)
if has_pres_rise and properties['apparatus']['kind'] == 'rapid compression machine':
raise KeywordError('Pressure rise cannot be defined for RCM.')
has_vol_hist = any(
[t.get('type') == 'volume' for dp in properties['datapoints']
for t in dp.get('time-histories', [{}])]
)
if has_vol_hist and properties['apparatus']['kind'] == 'shock tube':
raise KeywordError('Volume history cannot be defined for shock tube.')
if file_author_orcid and not file_author:
raise KeywordError('If file_author_orcid is specified, file_author must be as well')
if file_author:
temp_author = {'name': file_author}
if file_author_orcid:
temp_author['ORCID'] = file_author_orcid
properties['file-authors'].append(temp_author)
for idx in range(len(properties['datapoints'])):
for prop in properties['common-properties']:
properties['datapoints'][idx][prop] = properties['common-properties'][prop]
if validate:
chemked.ChemKED(dict_input=properties)
return properties |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cantera_composition_string'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '47', '233']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '22', '33']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'in'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'composition_type'}; {'id': '14', 'type': 'list', 'children': ['15', '16'], 'value': "['mole fraction', 'mass fraction']"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'mole fraction'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'mass fraction'"}, {'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': 'factor'}, {'id': '21', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '22', 'type': 'elif_clause', 'children': ['23', '28']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'composition_type'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'mole percent'"}; {'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': 'factor'}; {'id': '32', 'type': 'float', 'children': [], 'value': '100.0'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'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': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'Unknown composition type: {}'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'composition_type'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51', '80']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}; {'id': '50', 'type': 'None', 'children': []}, {'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': 'comps'}, {'id': '55', 'type': 'list_comprehension', 'children': ['56', '71']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'{!s}:{:.4e}'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'species_name'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '70'], 'value': '/'}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'magnitude'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'factor'}, {'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'composition'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82', '86', '215']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'comps'}, {'id': '85', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '95']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '88', 'type': 'call', 'children': ['89', '94']}, {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'composition'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '94', 'type': 'argument_list', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96', '106', '122', '132']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '105'], 'value': '/'}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'magnitude'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'factor'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'idents'}, {'id': '109', 'type': 'list_comprehension', 'children': ['110', '116']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '115', 'type': 'False', 'children': []}; {'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '118', 'type': 'list', 'children': ['119', '120', '121'], 'value': "['species_name', 'InChI', 'SMILES']"}, {'id': '119', 'type': 'string', 'children': [], 'value': "'species_name'"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'InChI'"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'SMILES'"}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'present'}, {'id': '125', 'type': 'list_comprehension', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'in'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}, {'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'idents'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138', '154']}, {'id': '133', 'type': 'not_operator', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'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': 'comps'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'{!s}:{:.4e}'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'species_name'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156', '182', '193', '202']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '169']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '168'], 'value': '>'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'list_comprehension', 'children': ['162', '163', '166']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '163', 'type': 'for_in_clause', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '166', 'type': 'if_clause', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'raise_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': "'More than one conversion present for species {}'"}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'species_name'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ident'}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'idents'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'True', 'children': []}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'species_replacement_name'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'comps'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'{!s}:{:.4e}'"}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'species_replacement_name'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '215', 'type': 'if_statement', 'children': ['216', '222']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '221'], 'value': '>'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}, {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'raise_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'string', 'children': [], 'value': "'Unknown species in conversion: {}'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'species_conversion'}, {'id': '233', 'type': 'return_statement', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'comps'} | def get_cantera_composition_string(self, species_conversion=None):
if self.composition_type in ['mole fraction', 'mass fraction']:
factor = 1.0
elif self.composition_type == 'mole percent':
factor = 100.0
else:
raise ValueError('Unknown composition type: {}'.format(self.composition_type))
if species_conversion is None:
comps = ['{!s}:{:.4e}'.format(c.species_name,
c.amount.magnitude/factor) for c in self.composition.values()]
else:
comps = []
for c in self.composition.values():
amount = c.amount.magnitude/factor
idents = [getattr(c, s, False) for s in ['species_name', 'InChI', 'SMILES']]
present = [i in species_conversion for i in idents]
if not any(present):
comps.append('{!s}:{:.4e}'.format(c.species_name, amount))
else:
if len([i for i in present if i]) > 1:
raise ValueError('More than one conversion present for species {}'.format(
c.species_name))
ident = idents[present.index(True)]
species_replacement_name = species_conversion.pop(ident)
comps.append('{!s}:{:.4e}'.format(species_replacement_name, amount))
if len(species_conversion) > 0:
raise ValueError('Unknown species in conversion: {}'.format(species_conversion))
return ', '.join(comps) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'family_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'question_name'}, {'id': '7', 'type': 'block', 'children': ['8', '16', '24', '32', '65', '75', '85', '95', '112', '132', '149', '156', '178', '268', '307', '346', '397']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'family_name'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'family_name'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'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': 'question_name'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'question_name'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'}; {'id': '34', 'type': 'string', 'children': [], 'value': "','"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'question_name'}; {'id': '36', 'type': 'block', 'children': ['37', '46', '52']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'name_split'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'question_name'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "','"}; {'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': 'name_split'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'question_name'}, {'id': '55', 'type': 'call', 'children': ['56', '64']}; {'id': '56', 'type': 'attribute', 'children': ['57', '63']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name_split'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'question_name'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'question_name'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '74', 'type': 'string', 'children': [], 'value': "''"}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "''"}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'family_name'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'family_name'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '94', 'type': 'string', 'children': [], 'value': "''"}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'None', 'children': []}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': 'r"[, \\-.]+"'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'num_family_names'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'None', 'children': []}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"[, .]+"'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'family_name'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'name_split'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'None', 'children': []}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'string', 'children': [], 'value': 'r"[, \\-.]+"'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'question_name'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'first_name'}; {'id': '152', 'type': 'list', 'children': ['153'], 'value': '[name_split[0]]'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'name_split'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '163']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '162'], 'value': '>'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'name_split'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'augmented_assignment', 'children': ['166', '167'], 'value': '+='}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '167', 'type': 'list_comprehension', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'name_split'}, {'id': '173', 'type': 'slice', 'children': ['174', '175', '176']}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '175', 'type': 'colon', 'children': []}; {'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'num_family_names'}; {'id': '178', 'type': 'if_statement', 'children': ['179', '195', '227']}, {'id': '179', 'type': 'boolean_operator', 'children': ['180', '186'], 'value': 'and'}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '185'], 'value': '>'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '191'], 'value': '=='}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'for_statement', 'children': ['197', '198', '206']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202']}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'first_name'}; {'id': '206', 'type': 'block', 'children': ['207', '217']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '212', 'type': 'subscript', 'children': ['213', '216']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '222']}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '222', 'type': 'subscript', 'children': ['223', '226']}, {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '227', 'type': 'elif_clause', 'children': ['228', '237']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '233'], 'value': '!='}, {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '237', 'type': 'block', 'children': ['238', '252', '260']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'min_names'}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '248']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'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': 'first_name'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '257', 'type': 'slice', 'children': ['258', '259']}; {'id': '258', 'type': 'colon', 'children': []}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'min_names'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '265', 'type': 'slice', 'children': ['266', '267']}; {'id': '266', 'type': 'colon', 'children': []}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'min_names'}; {'id': '268', 'type': 'if_statement', 'children': ['269', '286']}, {'id': '269', 'type': 'boolean_operator', 'children': ['270', '278'], 'value': 'or'}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '277'], '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': 'subscript', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'first_name'}; {'id': '276', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '278', 'type': 'comparison_operator', 'children': ['279', '285'], 'value': '=='}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '285', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '286', 'type': 'block', 'children': ['287', '297']}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '292']}, {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '291', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '292', 'type': 'subscript', 'children': ['293', '296']}, {'id': '293', 'type': 'subscript', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '295', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '301', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '302', 'type': 'subscript', 'children': ['303', '306']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '307', 'type': 'if_statement', 'children': ['308', '325']}; {'id': '308', 'type': 'boolean_operator', 'children': ['309', '317'], 'value': 'or'}, {'id': '309', 'type': 'comparison_operator', 'children': ['310', '316'], 'value': '>'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '317', 'type': 'comparison_operator', 'children': ['318', '324'], 'value': '>'}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'subscript', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '323', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '324', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '325', 'type': 'block', 'children': ['326', '336']}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'assignment', 'children': ['328', '331']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '330', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '331', 'type': 'subscript', 'children': ['332', '335']}; {'id': '332', 'type': 'subscript', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'given_name'}; {'id': '334', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '335', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '341']}; {'id': '338', 'type': 'subscript', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'first_name'}; {'id': '340', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '341', 'type': 'subscript', 'children': ['342', '345']}; {'id': '342', 'type': 'subscript', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'name_split'}; {'id': '344', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '345', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '346', 'type': 'if_statement', 'children': ['347', '354', '381']}, {'id': '347', 'type': 'boolean_operator', 'children': ['348', '351'], 'value': 'and'}; {'id': '348', 'type': 'comparison_operator', 'children': ['349', '350'], 'value': '=='}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'num_family_names'}; {'id': '350', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '351', 'type': 'comparison_operator', 'children': ['352', '353'], 'value': 'in'}; {'id': '352', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'family_name'}; {'id': '354', 'type': 'block', 'children': ['355', '364']}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'assignment', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'num_hyphen'}; {'id': '358', 'type': 'call', 'children': ['359', '362']}, {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'family_name'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}, {'id': '363', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '364', 'type': 'expression_statement', 'children': ['365']}, {'id': '365', 'type': 'assignment', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'family_name_compare'}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '371', 'type': 'argument_list', 'children': ['372']}; {'id': '372', 'type': 'subscript', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'name_split'}; {'id': '374', 'type': 'slice', 'children': ['375', '380']}, {'id': '375', 'type': 'unary_operator', 'children': ['376'], 'value': '-'}; {'id': '376', 'type': 'parenthesized_expression', 'children': ['377'], 'value': '()'}, {'id': '377', 'type': 'binary_operator', 'children': ['378', '379'], 'value': '+'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'num_hyphen'}, {'id': '379', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '380', 'type': 'colon', 'children': []}, {'id': '381', 'type': 'else_clause', 'children': ['382']}; {'id': '382', 'type': 'block', 'children': ['383']}, {'id': '383', 'type': 'expression_statement', 'children': ['384']}; {'id': '384', 'type': 'assignment', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'family_name_compare'}; {'id': '386', 'type': 'call', 'children': ['387', '390']}, {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '390', 'type': 'argument_list', 'children': ['391']}, {'id': '391', 'type': 'subscript', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'name_split'}, {'id': '393', 'type': 'slice', 'children': ['394', '396']}; {'id': '394', 'type': 'unary_operator', 'children': ['395'], 'value': '-'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'num_family_names'}; {'id': '396', 'type': 'colon', 'children': []}, {'id': '397', 'type': 'return_statement', 'children': ['398']}; {'id': '398', 'type': 'boolean_operator', 'children': ['399', '402'], 'value': 'and'}, {'id': '399', 'type': 'comparison_operator', 'children': ['400', '401'], 'value': '=='}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'given_name'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'first_name'}; {'id': '402', 'type': 'comparison_operator', 'children': ['403', '404'], 'value': '=='}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'family_name'} | def compare_name(given_name, family_name, question_name):
given_name = given_name.lower()
family_name = family_name.lower()
question_name = question_name.lower()
if ',' in question_name:
name_split = question_name.split(',')
name_split.reverse()
question_name = ' '.join(name_split).strip()
question_name = question_name.replace('.', '')
given_name = given_name.replace('.', '')
family_name = family_name.replace('.', '')
given_name = list(filter(None, re.split(r"[, \-.]+", given_name)))
num_family_names = len(list(filter(None, re.split("[, .]+", family_name))))
name_split = list(filter(None, re.split(r"[, \-.]+", question_name)))
first_name = [name_split[0]]
if len(name_split) > 2:
first_name += [n for n in name_split[1:-num_family_names]]
if len(first_name) > 1 and len(given_name) == len(first_name):
for i in range(1, len(first_name)):
first_name[i] = first_name[i][0]
given_name[i] = given_name[i][0]
elif len(given_name) != len(first_name):
min_names = min(len(given_name), len(first_name))
first_name = first_name[:min_names]
given_name = given_name[:min_names]
if len(first_name[0]) == 1 or len(given_name[0]) == 1:
given_name[0] = given_name[0][0]
first_name[0] = first_name[0][0]
if len(first_name[0]) > 1 or len(given_name[0]) > 1:
given_name[0] = given_name[0][0]
first_name[0] = name_split[0][0]
if num_family_names == 1 and '-' in family_name:
num_hyphen = family_name.count('-')
family_name_compare = '-'.join(name_split[-(num_hyphen + 1):])
else:
family_name_compare = ' '.join(name_split[-num_family_names:])
return given_name == first_name and family_name == family_name_compare |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_options'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'list_comprehension', 'children': ['8', '34']}; {'id': '8', 'type': 'dictionary', 'children': ['9', '14']}, {'id': '9', 'type': 'pair', 'children': ['10', '11']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'title'"}, {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '14', 'type': 'pair', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '16', 'type': 'parenthesized_expression', 'children': ['17'], 'value': '()'}, {'id': '17', 'type': 'conditional_expression', 'children': ['18', '24', '33'], 'value': 'if'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'-{0}'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '32'], 'value': '=='}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'default_order'"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'desc'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'for_in_clause', 'children': ['35', '38']}, {'id': '35', 'type': 'pattern_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '46']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'lambda', 'children': ['49', '51']}, {'id': '49', 'type': 'lambda_parameters', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'order'"}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'} | def sorted_options(sort_options):
return [
{
'title': v['title'],
'value': ('-{0}'.format(k)
if v.get('default_order', 'asc') == 'desc' else k),
}
for k, v in
sorted(sort_options.items(), key=lambda x: x[1].get('order', 0))
] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_files'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rootpath'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'directoryInFilter'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'directoryExFilter'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'compileInFilter'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'compileExFilter'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'contentInFilter'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'contentExFilter'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '36', '47', '58', '69', '80', '91', '132']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'directoryInFilter'}; {'id': '28', 'type': 'conditional_expression', 'children': ['29', '32', '35'], 'value': 'if'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'DirectoryInFilter'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'directoryInFilter'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'directoryInFilter'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'directoryExFilter'}, {'id': '39', 'type': 'conditional_expression', 'children': ['40', '43', '46'], 'value': 'if'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'DirectoryExFilter'}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'directoryExFilter'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'directoryExFilter'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'compileInFilter'}; {'id': '50', 'type': 'conditional_expression', 'children': ['51', '54', '57'], 'value': 'if'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'CompileInFilter'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'compileInFilter'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'compileInFilter'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'compileExFilter'}, {'id': '61', 'type': 'conditional_expression', 'children': ['62', '65', '68'], 'value': 'if'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'CompileExFilter'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'compileExFilter'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'compileExFilter'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'contentInFilter'}; {'id': '72', 'type': 'conditional_expression', 'children': ['73', '76', '79'], 'value': 'if'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ContentInFilter'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'contentInFilter'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'contentInFilter'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'contentExFilter'}, {'id': '83', 'type': 'conditional_expression', 'children': ['84', '87', '90'], 'value': 'if'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ContentExFilter'}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'contentExFilter'}, {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'contentExFilter'}, {'id': '91', 'type': 'function_definition', 'children': ['92', '93', '97']}; {'id': '92', 'type': 'function_name', 'children': [], 'value': 'filter'}, {'id': '93', 'type': 'parameters', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'explicit'}, {'id': '97', 'type': 'block', 'children': ['98', '115']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'explicit'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '104', 'type': 'generator_expression', 'children': ['105', '112']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'boolean_operator', 'children': ['117', '119'], 'value': 'or'}, {'id': '117', 'type': 'not_operator', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '121', 'type': 'generator_expression', 'children': ['122', '129']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '137', '143']}, {'id': '133', 'type': 'pattern_list', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dirnames'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rootpath'}, {'id': '143', 'type': 'block', 'children': ['144', '162']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'searchdir'}, {'id': '147', 'type': 'call', 'children': ['148', '153']}; {'id': '148', 'type': 'attribute', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'normpath'}, {'id': '153', 'type': 'argument_list', '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': 'os'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'normcase'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '169', '177']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'searchdir'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'directoryExFilter'}; {'id': '168', 'type': 'True', 'children': []}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '176']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'dirnames'}; {'id': '174', 'type': 'slice', 'children': ['175']}, {'id': '175', 'type': 'colon', 'children': []}; {'id': '176', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '177', 'type': 'elif_clause', 'children': ['178', '184']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182', '183']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'searchdir'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'directoryInFilter'}, {'id': '183', 'type': 'False', 'children': []}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'for_statement', 'children': ['186', '187', '200']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '187', 'type': 'list_comprehension', 'children': ['188', '197']}; {'id': '188', 'type': 'call', 'children': ['189', '194']}, {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'if_statement', 'children': ['202', '216', '226']}; {'id': '202', 'type': 'boolean_operator', 'children': ['203', '209'], 'value': 'and'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'compileInFilter'}; {'id': '208', 'type': 'False', 'children': []}, {'id': '209', 'type': 'not_operator', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214', '215']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'compileExFilter'}, {'id': '215', 'type': 'True', 'children': []}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '224']}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'CompileFiles'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '226', 'type': 'elif_clause', 'children': ['227', '241']}, {'id': '227', 'type': 'boolean_operator', 'children': ['228', '234'], 'value': 'and'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232', '233']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'contentInFilter'}, {'id': '233', 'type': 'False', 'children': []}; {'id': '234', 'type': 'not_operator', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '239', '240']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'contentExFilter'}; {'id': '240', 'type': 'True', 'children': []}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ContentFiles'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '249', 'type': 'argument_list', 'children': ['250']} | def insert_files(self, rootpath, directoryInFilter=None, directoryExFilter=None, compileInFilter=None, compileExFilter=None, contentInFilter=None, contentExFilter=None):
directoryInFilter = self.DirectoryInFilter if directoryInFilter is None else directoryInFilter
directoryExFilter = self.DirectoryExFilter if directoryExFilter is None else directoryExFilter
compileInFilter = self.CompileInFilter if compileInFilter is None else compileInFilter
compileExFilter = self.CompileExFilter if compileExFilter is None else compileExFilter
contentInFilter = self.ContentInFilter if contentInFilter is None else contentInFilter
contentExFilter = self.ContentExFilter if contentExFilter is None else contentExFilter
def filter(text, filters, explicit):
if explicit:
return any(fnmatch.fnmatch(text, f) for f in filters)
return not filters or any(fnmatch.fnmatch(text, f) for f in filters)
for root, dirnames, filenames in os.walk(rootpath):
searchdir = os.path.normpath(os.path.normcase(root))
if filter(searchdir, directoryExFilter, True):
dirnames[:] = []
elif filter(searchdir, directoryInFilter, False):
for filepath in [os.path.join(root, filename) for filename in filenames]:
if filter(filepath, compileInFilter, False) and not filter(filepath, compileExFilter, True):
self.CompileFiles.append(filepath)
elif filter(filepath, contentInFilter, False) and not filter(filepath, contentExFilter, True):
self.ContentFiles.append(filepath) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_variant'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 're_opts'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'compiled'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '19', '31', '42', '57', '65', '72', '85', '111', '117', '126', '132']}; {'id': '16', 'type': 'assert_statement', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"REQUIRE: Non-empty list."'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '26']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 're_opts'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 're_opts'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'default_re_opts'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': 'r")|("'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list_comprehension', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tc'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '64'], 'value': '+'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'}; {'id': '62', 'type': 'string', 'children': [], 'value': 'r"("'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '64', 'type': 'string', 'children': [], 'value': '")"'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'group_count'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'augmented_assignment', 'children': ['78', '79'], 'value': '+='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'group_count'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pattern_group_count'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '87', '99']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'compiled'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'convert_variant'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '__create_convert_variant_compiled'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 're_opts'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '99', 'type': 'else_clause', 'children': ['100']}; {'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': 'convert_variant'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '__create_convert_variant'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 're_opts'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'convert_variant'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'convert_variant'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'convert_variant'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'regex_group_count'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'group_count'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'convert_variant'} | def make_variant(cls, converters, re_opts=None, compiled=False, strict=True):
assert converters, "REQUIRE: Non-empty list."
if len(converters) == 1:
return converters[0]
if re_opts is None:
re_opts = cls.default_re_opts
pattern = r")|(".join([tc.pattern for tc in converters])
pattern = r"("+ pattern + ")"
group_count = len(converters)
for converter in converters:
group_count += pattern_group_count(converter.pattern)
if compiled:
convert_variant = cls.__create_convert_variant_compiled(converters,
re_opts, strict)
else:
convert_variant = cls.__create_convert_variant(re_opts, strict)
convert_variant.pattern = pattern
convert_variant.converters = tuple(converters)
convert_variant.regex_group_count = group_count
return convert_variant |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'info'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "''' Returns information on all the registered checkers.\n Sorted by namespace and then name\n :returns a list of CheckerInfo\n '''"}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '19']}; {'id': '12', 'type': 'call', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_checkers'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'lambda', 'children': ['22', '24']}; {'id': '22', 'type': 'lambda_parameters', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '24', 'type': 'tuple', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'} | def info(self):
''' Returns information on all the registered checkers.
Sorted by namespace and then name
:returns a list of CheckerInfo
'''
return sorted(self._checkers.values(), key=lambda x: (x.ns, x.name)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_from_text'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remove_duplicates'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '16', '24']}, {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'REGEX'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '24', 'type': 'if_clause', 'children': ['25']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '!='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '27', 'type': 'string', 'children': [], 'value': "''"} | def extract_from_text(text):
return tools.remove_duplicates([i[0]
for i in REGEX.findall(text) if i != '']) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_caveat'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cav'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'loc'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '15', '41', '51', '60', '120', '129', '154', '169', '201']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '\'\'\'Add a caveat to the macaroon.\n It encrypts it using the given key pair\n and by looking up the location using the given locator.\n As a special case, if the caveat\'s Location field has the prefix\n "local " the caveat is added as a client self-discharge caveat using\n the public key base64-encoded in the rest of the location. In this\n case, the Condition field must be empty. The resulting third-party\n caveat will encode the condition "true" encrypted with that public\n key.\n @param cav the checkers.Caveat to be added.\n @param key the public key to encrypt third party caveat.\n @param loc locator to find information on third parties when adding\n third party caveats. It is expected to have a third_party_info method\n that will be called with a location string and should return a\n ThirdPartyInfo instance holding the requested information.\n \'\'\''}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'is'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '40']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_macaroon'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'add_first_party_caveat'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '39']}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'resolve_caveat'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '40', 'type': 'return_statement', 'children': []}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'raise_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'no private key to encrypt third party caveat'"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'local_info'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_parse_local_location'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64', '97']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'local_info'}, {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'block', 'children': ['65', '69', '83']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'local_info'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '75']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': 'is'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '74', 'type': 'string', 'children': [], 'value': "''"}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'raise_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'concatenated_string', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'cannot specify caveat condition in '"}; {'id': '82', 'type': 'string', 'children': [], 'value': "'local third-party caveat'"}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cav'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'checkers'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Caveat'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '94']}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'local'"}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'true'"}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99', '109']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '102', 'type': 'None', 'children': []}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'raise_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'no locator when adding third party caveat'"}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'loc'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'third_party_info'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'root_key'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'urandom'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'integer', 'children': [], 'value': '24'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '137']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '<'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_version'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'version'}, {'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': 'info'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ThirdPartyInfo'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '149']}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_version'}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'public_key'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'public_key'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'caveat_info'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'encode_caveat'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '163', '164', '165', '166']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cav'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'condition'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'root_key'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_namespace'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '175', '180']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '<'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'VERSION_3'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'caveat_info'}; {'id': '180', 'type': 'else_clause', 'children': ['181']}, {'id': '181', 'type': 'block', 'children': ['182', '193']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_new_caveat_id'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '_caveat_id_prefix'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '200']}, {'id': '195', 'type': 'subscript', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_caveat_data'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'caveat_info'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': '_macaroon'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'add_third_party_caveat'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212', '213']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'root_key'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'id'} | def add_caveat(self, cav, key=None, loc=None):
'''Add a caveat to the macaroon.
It encrypts it using the given key pair
and by looking up the location using the given locator.
As a special case, if the caveat's Location field has the prefix
"local " the caveat is added as a client self-discharge caveat using
the public key base64-encoded in the rest of the location. In this
case, the Condition field must be empty. The resulting third-party
caveat will encode the condition "true" encrypted with that public
key.
@param cav the checkers.Caveat to be added.
@param key the public key to encrypt third party caveat.
@param loc locator to find information on third parties when adding
third party caveats. It is expected to have a third_party_info method
that will be called with a location string and should return a
ThirdPartyInfo instance holding the requested information.
'''
if cav.location is None:
self._macaroon.add_first_party_caveat(
self.namespace.resolve_caveat(cav).condition)
return
if key is None:
raise ValueError(
'no private key to encrypt third party caveat')
local_info = _parse_local_location(cav.location)
if local_info is not None:
info = local_info
if cav.condition is not '':
raise ValueError(
'cannot specify caveat condition in '
'local third-party caveat')
cav = checkers.Caveat(location='local', condition='true')
else:
if loc is None:
raise ValueError(
'no locator when adding third party caveat')
info = loc.third_party_info(cav.location)
root_key = os.urandom(24)
if self._version < info.version:
info = ThirdPartyInfo(
version=self._version,
public_key=info.public_key,
)
caveat_info = encode_caveat(
cav.condition, root_key, info, key, self._namespace)
if info.version < VERSION_3:
id = caveat_info
else:
id = self._new_caveat_id(self._caveat_id_prefix)
self._caveat_data[id] = caveat_info
self._macaroon.add_third_party_caveat(cav.location, root_key, id) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_new_caveat_id'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '15', '39', '48', '56']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''Return a third party caveat id\n This does not duplicate any third party caveat ids already inside\n macaroon. If base is non-empty, it is used as the id prefix.\n @param base bytes\n @return bytes\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bytearray'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22', '30']}; {'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': 'base'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'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': 'id'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'VERSION_3'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_caveat_data'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'caveats'}, {'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': '_macaroon'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'caveats'}; {'id': '56', 'type': 'while_statement', 'children': ['57', '58']}, {'id': '57', 'type': 'True', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59', '66', '72', '76', '99', '108']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '64', 'type': 'slice', 'children': ['65']}, {'id': '65', 'type': 'colon', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'encode_uvarint'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '75', 'type': 'False', 'children': []}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cav'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'caveats'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'if_statement', 'children': ['81', '93']}, {'id': '81', 'type': 'parenthesized_expression', 'children': ['82'], 'value': '()'}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '88'], 'value': 'and'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': 'is'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cav'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'verification_key_id'}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'cav'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'caveat_id'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '93', 'type': 'block', 'children': ['94', '98']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '97', 'type': 'True', 'children': []}; {'id': '98', 'type': 'break_statement', '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']}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'augmented_assignment', 'children': ['110', '111'], 'value': '+='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'} | def _new_caveat_id(self, base):
'''Return a third party caveat id
This does not duplicate any third party caveat ids already inside
macaroon. If base is non-empty, it is used as the id prefix.
@param base bytes
@return bytes
'''
id = bytearray()
if len(base) > 0:
id.extend(base)
else:
id.append(VERSION_3)
i = len(self._caveat_data)
caveats = self._macaroon.caveats
while True:
temp = id[:]
encode_uvarint(i, temp)
found = False
for cav in caveats:
if (cav.verification_key_id is not None
and cav.caveat_id == temp):
found = True
break
if not found:
return bytes(temp)
i += 1 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_macaroons'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'headers_or_request'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '37', '41', '95', '102', '144', '151', '170']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "''' Returns an array of any macaroons found in the given slice of cookies.\n If the argument implements a get_header method, that will be used\n instead of the get method to retrieve headers.\n @param headers_or_request: dict of headers or a\n urllib.request.Request-like object.\n @return: A list of list of mpy macaroons\n '''"}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '15']}, {'id': '9', 'type': 'function_name', 'children': [], 'value': 'get_header'}; {'id': '10', 'type': 'parameters', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '26']}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'headers_or_request'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_header'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '26', 'type': 'except_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'headers_or_request'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'mss'}; {'id': '40', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '41', 'type': 'function_definition', 'children': ['42', '43', '45']}; {'id': '42', 'type': 'function_name', 'children': [], 'value': 'add_macaroon'}, {'id': '43', 'type': 'parameters', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '45', 'type': 'block', 'children': ['46', '75', '88']}; {'id': '46', 'type': 'try_statement', 'children': ['47', '71']}, {'id': '47', 'type': 'block', 'children': ['48', '57']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'b64decode'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data_as_objs'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '71', 'type': 'except_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '85']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'macaroon_from_dict'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data_as_objs'}; {'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': 'mss'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ms'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cookie_header'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_header'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'Cookie'"}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cookie_header'}, {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'block', 'children': ['107', '113', '123']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cs'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'SimpleCookie'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'cs'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'cookie_header'}, {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cs'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '134']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'string', 'children': [], 'value': "'macaroon-'"}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'add_macaroon'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'cs'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'macaroon_header'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'get_header'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'Macaroons'"}, {'id': '151', 'type': 'if_statement', 'children': ['152', '155']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'macaroon_header'}; {'id': '154', 'type': 'None', 'children': []}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '164']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'macaroon_header'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'string', 'children': [], 'value': "','"}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'add_macaroon'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '170', 'type': 'return_statement', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'mss'} | def extract_macaroons(headers_or_request):
''' Returns an array of any macaroons found in the given slice of cookies.
If the argument implements a get_header method, that will be used
instead of the get method to retrieve headers.
@param headers_or_request: dict of headers or a
urllib.request.Request-like object.
@return: A list of list of mpy macaroons
'''
def get_header(key, default=None):
try:
return headers_or_request.get_header(key, default)
except AttributeError:
return headers_or_request.get(key, default)
mss = []
def add_macaroon(data):
try:
data = utils.b64decode(data)
data_as_objs = json.loads(data.decode('utf-8'))
except ValueError:
return
ms = [utils.macaroon_from_dict(x) for x in data_as_objs]
mss.append(ms)
cookie_header = get_header('Cookie')
if cookie_header is not None:
cs = SimpleCookie()
cs.load(str(cookie_header))
for c in cs:
if c.startswith('macaroon-'):
add_macaroon(cs[c].value)
macaroon_header = get_header('Macaroons')
if macaroon_header is not None:
for h in macaroon_header.split(','):
add_macaroon(h)
return mss |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'http_error_handler'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '5', 'type': 'block', 'children': ['6', '50', '87', '302']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': 'hrefs_to_resources'}; {'id': '8', 'type': 'parameters', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'hrefs'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '24']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'href'}, {'id': '13', 'type': 'call', 'children': ['14', '23']}; {'id': '14', 'type': 'attribute', 'children': ['15', '22']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'hrefs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "','"}, {'id': '21', 'type': 'string', 'children': [], 'value': "''"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '41']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '30', 'type': 'subscript', 'children': ['31', '37']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'href'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '37', 'type': 'slice', 'children': ['38', '40']}; {'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '40', 'type': 'colon', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'yield', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Resource'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']}, {'id': '51', 'type': 'function_name', 'children': [], 'value': 'hrefs_list_to_resources'}; {'id': '52', 'type': 'parameters', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'hrefs_list'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '61']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'href'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'eval'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'hrefs_list'}, {'id': '61', 'type': 'block', 'children': ['62', '78']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '67', 'type': 'subscript', 'children': ['68', '74']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'href'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '74', 'type': 'slice', 'children': ['75', '77']}, {'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '77', 'type': 'colon', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'yield', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Resource'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '87', 'type': 'decorated_definition', 'children': ['88', '93']}; {'id': '88', 'type': 'decorator', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'wraps'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '93', 'type': 'function_definition', 'children': ['94', '95', '101']}; {'id': '94', 'type': 'function_name', 'children': [], 'value': 'wrapper'}, {'id': '95', 'type': 'parameters', 'children': ['96', '97', '99']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'list_splat_pattern', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '99', 'type': 'dictionary_splat_pattern', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'try_statement', 'children': ['103', '113']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '111']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'list_splat', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '111', 'type': 'dictionary_splat', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '113', 'type': 'except_clause', 'children': ['114', '118']}; {'id': '114', 'type': 'as_pattern', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'HttpError'}; {'id': '116', 'type': 'as_pattern_target', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '118', 'type': 'block', 'children': ['119', '301']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '125', '162']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '124'], 'value': '=='}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'http_status'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '404'}, {'id': '125', 'type': 'block', 'children': ['126', '134']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'emit'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'deleted'"}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '140', '148']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'Resource'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'raise_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ResourceNotFound'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'resource'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'elif_clause', 'children': ['149', '154']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'Collection'}; {'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': 'CollectionNotFound'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'elif_clause', 'children': ['163', '168']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': '=='}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'http_status'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '409'}; {'id': '168', 'type': 'block', 'children': ['169', '181', '202', '214', '235', '247', '268', '280']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': "r'^Delete when children still present: (\\[[^]]*\\])'"}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'raise_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ChildrenExists'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'hrefs_list_to_resources'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': "r'^Delete when resource still referred: (\\[[^]]*\\])'"}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'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': 'BackRefsExists'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'resources'}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'hrefs_list_to_resources'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}, {'id': '243', 'type': 'string', 'children': [], 'value': "r'^Children (.*) still exist$'"}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'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': 'ChildrenExists'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'hrefs_to_resources'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '275', 'type': 'argument_list', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': "r'^Back-References from (.*) still exist$'"}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '280', 'type': 'if_statement', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '282', 'type': 'block', 'children': ['283']}, {'id': '283', 'type': 'raise_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'BackRefsExists'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'resources'}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'hrefs_to_resources'}; {'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': 'matches'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '301', 'type': 'raise_statement', 'children': []}; {'id': '302', 'type': 'return_statement', 'children': ['303']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'wrapper'} | def http_error_handler(f):
def hrefs_to_resources(hrefs):
for href in hrefs.replace(',', '').split():
type, uuid = href.split('/')[-2:]
yield Resource(type, uuid=uuid)
def hrefs_list_to_resources(hrefs_list):
for href in eval(hrefs_list):
type, uuid = href.split('/')[-2:]
yield Resource(type, uuid=uuid)
@wraps(f)
def wrapper(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except HttpError as e:
if e.http_status == 404:
self.emit('deleted', self)
if isinstance(self, Resource):
raise ResourceNotFound(resource=self)
elif isinstance(self, Collection):
raise CollectionNotFound(collection=self)
elif e.http_status == 409:
matches = re.match(r'^Delete when children still present: (\[[^]]*\])', e.message)
if matches:
raise ChildrenExists(
resources=list(hrefs_list_to_resources(matches.group(1))))
matches = re.match(r'^Delete when resource still referred: (\[[^]]*\])', e.message)
if matches:
raise BackRefsExists(
resources=list(hrefs_list_to_resources(matches.group(1))))
matches = re.match(r'^Children (.*) still exist$', e.message)
if matches:
raise ChildrenExists(
resources=list(hrefs_to_resources(matches.group(1))))
matches = re.match(r'^Back-References from (.*) still exist$', e.message)
if matches:
raise BackRefsExists(
resources=list(hrefs_to_resources(matches.group(1))))
raise
return wrapper |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_windows'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '70', '81', '85', '149', '171', '186', '325', '457']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_keyname'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'GetKey'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '32']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'in'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Message'}, {'id': '25', 'type': 'binary_operator', 'children': ['26', '29'], 'value': '+'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'KEYS_UP'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'KEYS_DOWN'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '39']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}, {'id': '39', 'type': 'block', 'children': ['40', '54']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '47']}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_realmodifiers'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': 'in'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Message'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'KEYS_DOWN'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '65']}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_modifiers'}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '65', 'type': 'subscript', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_realmodifiers'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '78']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': 'not'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'Message'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'KEYS_DOWN'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'True', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'is_altgr'}; {'id': '84', 'type': 'False', 'children': []}, {'id': '85', 'type': 'if_statement', 'children': ['86', '97', '106', '123']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '94'], 'value': 'in'}, {'id': '87', 'type': 'tuple', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'IsExtended'}, {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'NUMPAD_SPECIALS'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"Numpad-"'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '106', 'type': 'elif_clause', 'children': ['107', '118']}, {'id': '107', 'type': 'boolean_operator', 'children': ['108', '112'], 'value': 'or'}; {'id': '108', 'type': 'not_operator', 'children': ['109']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'Ascii'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': '"Numpad"'}; {'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': 'key'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'vkey'}, {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125', '135']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'is_altgr'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': 'in'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'Ascii'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ALT_GRS'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_keyname'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'unichr'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Ascii'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}, {'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': '"Adding key %s (real %s)"'}; {'id': '158', 'type': 'tuple', 'children': ['159', '165']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'string', 'children': [], 'value': '"utf-8"'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"utf-8"'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_output'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '180', '183']}, {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '179', 'type': 'string', 'children': [], 'value': '"keys"'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '195']}, {'id': '187', 'type': 'boolean_operator', 'children': ['188', '193'], 'value': 'and'}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'not'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'vkey'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}, {'id': '193', 'type': 'not_operator', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'is_altgr'}, {'id': '195', 'type': 'block', 'children': ['196', '218']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'modifier'}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '203', 'type': 'generator_expression', 'children': ['204', '205', '212']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '205', 'type': 'for_in_clause', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '207', 'type': 'list', 'children': ['208', '209', '210', '211'], 'value': '["Ctrl", "Alt", "Shift", "Win"]'}; {'id': '208', 'type': 'string', 'children': [], 'value': '"Ctrl"'}, {'id': '209', 'type': 'string', 'children': [], 'value': '"Alt"'}; {'id': '210', 'type': 'string', 'children': [], 'value': '"Shift"'}, {'id': '211', 'type': 'string', 'children': [], 'value': '"Win"'}; {'id': '212', 'type': 'if_clause', 'children': ['213']}, {'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': '_modifiers'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '224']}, {'id': '219', 'type': 'boolean_operator', 'children': ['220', '221'], 'value': 'and'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'modifier'}, {'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '!='}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'modifier'}, {'id': '223', 'type': 'string', 'children': [], 'value': '"Shift"'}; {'id': '224', 'type': 'block', 'children': ['225', '250', '272', '280', '288', '310']}, {'id': '225', 'type': 'if_statement', 'children': ['226', '235']}; {'id': '226', 'type': 'boolean_operator', 'children': ['227', '232'], 'value': 'and'}, {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': '_modifiers'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"Ctrl"'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'Ascii'}, {'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': 'key'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': '_keyname'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'unichr'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'KeyID'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'realmodifier'}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '257', 'type': 'generator_expression', 'children': ['258', '259', '270']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '259', 'type': 'for_in_clause', 'children': ['260', '263']}; {'id': '260', 'type': 'pattern_list', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '263', 'type': 'call', 'children': ['264', '269']}; {'id': '264', 'type': 'attribute', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': '_realmodifiers'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '269', 'type': 'argument_list', 'children': []}; {'id': '270', 'type': 'if_clause', 'children': ['271']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '%'}; {'id': '276', 'type': 'string', 'children': [], 'value': '"%s-%s"'}, {'id': '277', 'type': 'tuple', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'realmodifier'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '%'}; {'id': '284', 'type': 'string', 'children': [], 'value': '"%s-%s"'}, {'id': '285', 'type': 'tuple', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'modifier'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '288', 'type': 'if_statement', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '%'}; {'id': '296', 'type': 'string', 'children': [], 'value': '"Adding combo %s (real %s)"'}, {'id': '297', 'type': 'tuple', 'children': ['298', '304']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': '_output'}, {'id': '315', 'type': 'argument_list', 'children': ['316', '319', '322']}; {'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '318', 'type': 'string', 'children': [], 'value': '"combos"'}, {'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'realkey'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '325', 'type': 'if_statement', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}, {'id': '327', 'type': 'block', 'children': ['328', '335', '349', '363', '377', '391', '405', '417', '429', '441', '453']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '%'}, {'id': '333', 'type': 'string', 'children': [], 'value': '"CHARACTER: %r"'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'string', 'children': [], 'value': "'GetKey: {0}'"}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'GetKey'}; {'id': '348', 'type': 'argument_list', 'children': []}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'string', 'children': [], 'value': "'IsAlt: {0}'"}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'call', 'children': ['359', '362']}, {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'IsAlt'}; {'id': '362', 'type': 'argument_list', 'children': []}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'call', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'string', 'children': [], 'value': "'IsExtended: {0}'"}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '371', 'type': 'argument_list', 'children': ['372']}; {'id': '372', 'type': 'call', 'children': ['373', '376']}, {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'IsExtended'}; {'id': '376', 'type': 'argument_list', 'children': []}, {'id': '377', 'type': 'expression_statement', 'children': ['378']}; {'id': '378', 'type': 'call', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}, {'id': '381', 'type': 'call', 'children': ['382', '385']}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'string', 'children': [], 'value': "'IsInjected: {0}'"}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '385', 'type': 'argument_list', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '390']}, {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'IsInjected'}; {'id': '390', 'type': 'argument_list', 'children': []}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'call', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}, {'id': '395', 'type': 'call', 'children': ['396', '399']}; {'id': '396', 'type': 'attribute', 'children': ['397', '398']}, {'id': '397', 'type': 'string', 'children': [], 'value': "'IsTransition: {0}'"}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '399', 'type': 'argument_list', 'children': ['400']}; {'id': '400', 'type': 'call', 'children': ['401', '404']}, {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'IsTransition'}; {'id': '404', 'type': 'argument_list', 'children': []}, {'id': '405', 'type': 'expression_statement', 'children': ['406']}; {'id': '406', 'type': 'call', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'call', 'children': ['410', '413']}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'string', 'children': [], 'value': "'ASCII: {0}'"}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '413', 'type': 'argument_list', 'children': ['414']}; {'id': '414', 'type': 'attribute', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'Ascii'}, {'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': 'call', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}, {'id': '423', 'type': 'string', 'children': [], 'value': "'KeyID: {0}'"}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '425', 'type': 'argument_list', 'children': ['426']}; {'id': '426', 'type': 'attribute', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'KeyID'}, {'id': '429', 'type': 'expression_statement', 'children': ['430']}; {'id': '430', 'type': 'call', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '432', 'type': 'argument_list', 'children': ['433']}, {'id': '433', 'type': 'call', 'children': ['434', '437']}; {'id': '434', 'type': 'attribute', 'children': ['435', '436']}, {'id': '435', 'type': 'string', 'children': [], 'value': "'ScanCode: {0}'"}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '437', 'type': 'argument_list', 'children': ['438']}; {'id': '438', 'type': 'attribute', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'ScanCode'}, {'id': '441', 'type': 'expression_statement', 'children': ['442']}; {'id': '442', 'type': 'call', 'children': ['443', '444']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '444', 'type': 'argument_list', 'children': ['445']}, {'id': '445', 'type': 'call', 'children': ['446', '449']}; {'id': '446', 'type': 'attribute', 'children': ['447', '448']}, {'id': '447', 'type': 'string', 'children': [], 'value': "'Message: {0}'"}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '449', 'type': 'argument_list', 'children': ['450']}; {'id': '450', 'type': 'attribute', 'children': ['451', '452']}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'Message'}, {'id': '453', 'type': 'expression_statement', 'children': ['454']}; {'id': '454', 'type': 'call', 'children': ['455', '456']}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '456', 'type': 'argument_list', 'children': []}, {'id': '457', 'type': 'return_statement', 'children': ['458']} | def _handle_windows(self, event):
vkey = self._keyname(event.GetKey())
if event.Message in self.KEYS_UP + self.KEYS_DOWN:
if vkey in self.MODIFIERNAMES:
self._realmodifiers[vkey] = event.Message in self.KEYS_DOWN
self._modifiers[self.MODIFIERNAMES[vkey]] = self._realmodifiers[vkey]
if event.Message not in self.KEYS_DOWN:
return True
is_altgr = False
if (vkey, event.IsExtended()) in self.NUMPAD_SPECIALS:
key = vkey = "Numpad-" + vkey
elif not event.Ascii or vkey.startswith("Numpad"):
key = vkey
else:
is_altgr = event.Ascii in self.ALT_GRS
key = self._keyname(unichr(event.Ascii))
if DEBUG: print("Adding key %s (real %s)" % (key.encode("utf-8"), vkey.encode("utf-8")))
self._output(type="keys", key=key, realkey=vkey)
if vkey not in self.MODIFIERNAMES and not is_altgr:
modifier = "-".join(k for k in ["Ctrl", "Alt", "Shift", "Win"]
if self._modifiers[k])
if modifier and modifier != "Shift":
if self._modifiers["Ctrl"] and event.Ascii:
key = self._keyname(unichr(event.KeyID))
realmodifier = "-".join(k for k, v in self._realmodifiers.items() if v)
realkey = "%s-%s" % (realmodifier, key)
key = "%s-%s" % (modifier, key)
if DEBUG: print("Adding combo %s (real %s)" % (key.encode("utf-8"), realkey.encode("utf-8")))
self._output(type="combos", key=key, realkey=realkey)
if DEBUG:
print("CHARACTER: %r" % key)
print('GetKey: {0}'.format(event.GetKey()))
print('IsAlt: {0}'.format(event.IsAlt()))
print('IsExtended: {0}'.format(event.IsExtended()))
print('IsInjected: {0}'.format(event.IsInjected()))
print('IsTransition: {0}'.format(event.IsTransition()))
print('ASCII: {0}'.format(event.Ascii))
print('KeyID: {0}'.format(event.KeyID))
print('ScanCode: {0}'.format(event.ScanCode))
print('Message: {0}'.format(event.Message))
print()
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_linux'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keycode'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'press'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '25', '52', '70']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_keyname'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keycode'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}, {'id': '31', 'type': 'block', 'children': ['32', '44']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '43']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_modifiers'}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'press'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '51']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_realmodifiers'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'press'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'press'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_output'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '64', '67']}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"keys"'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '78']}, {'id': '71', 'type': 'boolean_operator', 'children': ['72', '73'], 'value': 'and'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'press'}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'not'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'MODIFIERNAMES'}; {'id': '78', 'type': 'block', 'children': ['79', '101']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '86', 'type': 'generator_expression', 'children': ['87', '88', '95']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '90', 'type': 'list', 'children': ['91', '92', '93', '94'], 'value': '["Ctrl", "Alt", "Shift", "Win"]'}, {'id': '91', 'type': 'string', 'children': [], 'value': '"Ctrl"'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"Alt"'}, {'id': '93', 'type': 'string', 'children': [], 'value': '"Shift"'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"Win"'}, {'id': '95', 'type': 'if_clause', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_modifiers'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '101', 'type': 'if_statement', 'children': ['102', '107']}; {'id': '102', 'type': 'boolean_operator', 'children': ['103', '104'], 'value': 'and'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '!='}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'modifier'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Shift"'}, {'id': '107', 'type': 'block', 'children': ['108', '130', '138', '146', '168']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'realmodifier'}, {'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': 'generator_expression', 'children': ['116', '117', '128']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'pattern_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '_realmodifiers'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '127', 'type': 'argument_list', 'children': []}; {'id': '128', 'type': 'if_clause', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"%s-%s"'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'realmodifier'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"%s-%s"'}, {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'modifier'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'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': 'print'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'}; {'id': '154', 'type': 'string', 'children': [], 'value': '"Adding combo %s (real %s)"'}, {'id': '155', 'type': 'tuple', 'children': ['156', '162']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'realkey'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'string', 'children': [], 'value': '"utf-8"'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_output'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '177', '180']}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"combos"'}, {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'realkey'} | def _handle_linux(self, keycode, character, press):
if character is None: return
key = self._keyname(character, keycode)
if key in self.MODIFIERNAMES:
self._modifiers[self.MODIFIERNAMES[key]] = press
self._realmodifiers[key] = press
if press:
self._output(type="keys", key=key, realkey=key)
if press and key not in self.MODIFIERNAMES:
modifier = "-".join(k for k in ["Ctrl", "Alt", "Shift", "Win"]
if self._modifiers[k])
if modifier and modifier != "Shift":
realmodifier = "-".join(k for k, v in self._realmodifiers.items() if v)
realkey = "%s-%s" % (realmodifier, key)
key = "%s-%s" % (modifier, key)
if DEBUG: print("Adding combo %s (real %s)" % (key.encode("utf-8"), realkey.encode("utf-8")))
self._output(type="combos", key=key, realkey=realkey) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_store_documentation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'html'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'quiet'}, {'id': '9', 'type': 'block', 'children': ['10', '15', '26', '44', '66', '91', '116', '149', '153', '212', '217', '230', '237', '241', '262', '274']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"Storing groundwork application documents\\n"'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"Application: %s"'}, {'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': 'app'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Number of documents: %s\\n"'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '54']}, {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '52']}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isabs'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '76']}, {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '76', 'type': 'block', 'children': ['77', '84']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"Path %s is not a directory!"'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '101']}; {'id': '92', 'type': 'not_operator', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '99']}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '101', 'type': 'block', 'children': ['102', '109']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '%'}, {'id': '107', 'type': 'string', 'children': [], 'value': '"Path %s does not exist"'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'}, {'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': 'sys'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'for_statement', 'children': ['117', '121', '127']}, {'id': '117', 'type': 'pattern_list', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dirpath'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dirnames'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'files'}, {'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': 'walk'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '130', 'type': 'block', 'children': ['131', '138']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '%'}; {'id': '136', 'type': 'string', 'children': [], 'value': '"Path %s is not empty!\\n"'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '141']}, {'id': '139', 'type': 'not_operator', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'overwrite'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '152', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '153', 'type': 'for_statement', 'children': ['154', '157', '170']}; {'id': '154', 'type': 'pattern_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '157', 'type': 'call', 'children': ['158', '169']}; {'id': '158', 'type': 'attribute', 'children': ['159', '168']}, {'id': '159', 'type': 'call', 'children': ['160', '167']}; {'id': '160', 'type': 'attribute', 'children': ['161', '166']}, {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'block', 'children': ['171', '178', '190', '199', '203']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'file_extension'}; {'id': '174', 'type': 'conditional_expression', 'children': ['175', '176', '177'], 'value': 'if'}, {'id': '175', 'type': 'string', 'children': [], 'value': '".html"'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'html'}, {'id': '177', 'type': 'string', 'children': [], 'value': '".rst"'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'file_name_parts'}, {'id': '181', 'type': 'call', 'children': ['182', '189']}; {'id': '182', 'type': 'attribute', 'children': ['183', '188']}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '187', 'type': 'argument_list', 'children': []}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'file_name'}, {'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': 'identifier', 'children': [], 'value': 'file_name_parts'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'augmented_assignment', 'children': ['201', '202'], 'value': '+='}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'file_extension'}, {'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': 'documents'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'tuple', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'file_name'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'string', 'children': [], 'value': '"Going to write to following files:"'}, {'id': '217', 'type': 'for_statement', 'children': ['218', '219', '220']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '%'}; {'id': '226', 'type': 'string', 'children': [], 'value': '" %s"'}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '%'}, {'id': '235', 'type': 'string', 'children': [], 'value': '"\\nTarget directory: %s"'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '240', 'type': 'None', 'children': []}, {'id': '241', 'type': 'while_statement', 'children': ['242', '250']}; {'id': '242', 'type': 'boolean_operator', 'children': ['243', '248'], 'value': 'and'}, {'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'not'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'answer'}, {'id': '245', 'type': 'list', 'children': ['246', '247'], 'value': '["N", "Y"]'}; {'id': '246', 'type': 'string', 'children': [], 'value': '"N"'}, {'id': '247', 'type': 'string', 'children': [], 'value': '"Y"'}; {'id': '248', 'type': 'not_operator', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'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': 'answer'}; {'id': '254', 'type': 'call', 'children': ['255', '261']}, {'id': '255', 'type': 'attribute', 'children': ['256', '260']}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'prompt'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'string', 'children': [], 'value': '"Shall we go on? [Y]es, [N]o: "'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '261', 'type': 'argument_list', 'children': []}; {'id': '262', 'type': 'if_statement', 'children': ['263', '266']}, {'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': '=='}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'answer'}, {'id': '265', 'type': 'string', 'children': [], 'value': '"N"'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '274', 'type': 'for_statement', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'try_statement', 'children': ['279', '361', '378']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'with_statement', 'children': ['281', '301']}, {'id': '281', 'type': 'with_clause', 'children': ['282']}; {'id': '282', 'type': 'with_item', 'children': ['283']}, {'id': '283', 'type': 'as_pattern', 'children': ['284', '299']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '298']}, {'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': 'os'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '297', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '298', 'type': 'string', 'children': [], 'value': '"w"'}, {'id': '299', 'type': 'as_pattern_target', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'doc_file'}, {'id': '301', 'type': 'block', 'children': ['302', '333', '354']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'doc_rendered'}, {'id': '305', 'type': 'call', 'children': ['306', '320']}; {'id': '306', 'type': 'attribute', 'children': ['307', '319']}, {'id': '307', 'type': 'call', 'children': ['308', '313']}; {'id': '308', 'type': 'attribute', 'children': ['309', '312']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'Environment'}, {'id': '311', 'type': 'argument_list', 'children': []}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'from_string'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'attribute', 'children': ['315', '318']}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'render'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '326']}, {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'plugin'}; {'id': '328', 'type': 'attribute', 'children': ['329', '332']}, {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '331', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'plugin'}, {'id': '333', 'type': 'if_statement', 'children': ['334', '335', '348']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'html'}, {'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': 'output'}, {'id': '339', 'type': 'subscript', 'children': ['340', '347']}; {'id': '340', 'type': 'call', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'publish_parts'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'doc_rendered'}; {'id': '344', 'type': 'keyword_argument', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'writer_name'}; {'id': '346', 'type': 'string', 'children': [], 'value': '"html"'}, {'id': '347', 'type': 'string', 'children': [], 'value': "'whole'"}; {'id': '348', 'type': 'else_clause', 'children': ['349']}, {'id': '349', 'type': 'block', 'children': ['350']}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'assignment', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'doc_rendered'}; {'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': 'doc_file'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '361', 'type': 'except_clause', 'children': ['362', '366']}; {'id': '362', 'type': 'as_pattern', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '364', 'type': 'as_pattern_target', 'children': ['365']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '366', 'type': 'block', 'children': ['367']}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'binary_operator', 'children': ['372', '373'], 'value': '%'}; {'id': '372', 'type': 'string', 'children': [], 'value': '"%s error occurred: %s"'}, {'id': '373', 'type': 'tuple', 'children': ['374', '377']}; {'id': '374', 'type': 'subscript', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '376', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '378', 'type': 'else_clause', 'children': ['379']}, {'id': '379', 'type': 'block', 'children': ['380']}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}, {'id': '381', 'type': 'call', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '383', 'type': 'argument_list', 'children': ['384']}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '386'], 'value': '%'}, {'id': '385', 'type': 'string', 'children': [], 'value': '"%s stored."'}; {'id': '386', 'type': 'subscript', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'document'} | def _store_documentation(self, path, html, overwrite, quiet):
echo("Storing groundwork application documents\n")
echo("Application: %s" % self.app.name)
echo("Number of documents: %s\n" % len(self.app.documents.get()))
if not os.path.isabs(path):
path = os.path.abspath(path)
if not os.path.isdir(path):
echo("Path %s is not a directory!" % path)
sys.exit(1)
if not os.path.exists(path):
echo("Path %s does not exist" % path)
sys.exit(1)
for dirpath, dirnames, files in os.walk(path):
if files:
echo("Path %s is not empty!\n" % path)
if not overwrite:
sys.exit(1)
documents = []
for key, document in self.app.documents.get().items():
file_extension = ".html" if html else ".rst"
file_name_parts = key.lower().split()
file_name = "".join(file_name_parts)
file_name += file_extension
documents.append((file_name, document))
echo("Going to write to following files:")
for document in documents:
echo(" %s" % document[0])
echo("\nTarget directory: %s" % path)
answer = None
while answer not in ["N", "Y"] and not quiet:
answer = prompt("Shall we go on? [Y]es, [N]o: ").upper()
if answer == "N":
sys.exit(0)
for document in documents:
try:
with open(os.path.join(path, document[0]), "w") as doc_file:
doc_rendered = Environment().from_string(document[1].content).render(app=self.app,
plugin=document[1].plugin)
if html:
output = publish_parts(doc_rendered, writer_name="html")['whole']
else:
output = doc_rendered
doc_file.write(output)
except Exception as e:
echo("%s error occurred: %s" % (document[0], e))
else:
echo("%s stored." % document[0]) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_show_documentation'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '42', '57', '70', '87', '91', '95']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '27']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '14', 'type': 'call', 'children': ['15', '26']}, {'id': '15', 'type': 'attribute', 'children': ['16', '25']}; {'id': '16', 'type': 'call', 'children': ['17', '24']}, {'id': '17', 'type': 'attribute', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '!='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"main"'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'lambda', 'children': ['52', '54']}; {'id': '52', 'type': 'lambda_parameters', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'main'}; {'id': '60', 'type': 'call', 'children': ['61', '68']}, {'id': '61', 'type': 'attribute', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"main"'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'main'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}, {'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': 'documents'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'tuple', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'main'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'main'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'user_answer'}; {'id': '90', 'type': 'string', 'children': [], 'value': '""'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'while_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '!='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'user_answer'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"X"'}, {'id': '99', 'type': 'block', 'children': ['100', '109', '128', '136', '150', '178', '192', '202', '207', '217', '221', '235', '244', '248', '253', '282', '296']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '<'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '118']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '>'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '117'], 'value': '-'}, {'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': 'documents'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'index'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '127'], 'value': '-'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '131', 'type': 'subscript', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'os'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'system'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'conditional_expression', 'children': ['143', '144', '149'], 'value': 'if'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'cls'"}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': '=='}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'nt'"}, {'id': '149', 'type': 'string', 'children': [], 'value': "'clear'"}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '167']}, {'id': '155', 'type': 'attribute', 'children': ['156', '166']}; {'id': '156', 'type': 'call', 'children': ['157', '162']}, {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'Environment'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'from_string'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '173']}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'plugin'}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'plugin'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '%'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"This document is registered by \'%s\' under the name \'%s\'"'}, {'id': '183', 'type': 'tuple', 'children': ['184', '189']}; {'id': '184', 'type': 'attribute', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'plugin'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'document'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '*'}, {'id': '197', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '*'}; {'id': '212', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"Actions: "'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '230']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '<'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '229'], 'value': '-'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'augmented_assignment', 'children': ['233', '234'], 'value': '+='}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '234', 'type': 'string', 'children': [], 'value': '"[N]ext, "'}, {'id': '235', 'type': 'if_statement', 'children': ['236', '239']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'augmented_assignment', 'children': ['242', '243'], 'value': '+='}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '243', 'type': 'string', 'children': [], 'value': '"[P]revious, "'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'augmented_assignment', 'children': ['246', '247'], 'value': '+='}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '247', 'type': 'string', 'children': [], 'value': '"E[x]it"'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '253', 'type': 'if_statement', 'children': ['254', '262', '267', '276']}; {'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': '<'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '261'], 'value': '-'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'documents'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '266', 'type': 'string', 'children': [], 'value': '"N"'}, {'id': '267', 'type': 'elif_clause', 'children': ['268', '271']}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': '>'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '275', 'type': 'string', 'children': [], 'value': '"P"'}; {'id': '276', 'type': 'else_clause', 'children': ['277']}, {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '281', 'type': 'string', 'children': [], 'value': '"X"'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'user_answer'}, {'id': '285', 'type': 'call', 'children': ['286', '295']}; {'id': '286', 'type': 'attribute', 'children': ['287', '294']}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'prompt'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': '"Select your action"'}, {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '295', 'type': 'argument_list', 'children': []}; {'id': '296', 'type': 'if_statement', 'children': ['297', '300', '305']}, {'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '=='}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'user_answer'}, {'id': '299', 'type': 'string', 'children': [], 'value': '"N"'}; {'id': '300', 'type': 'block', 'children': ['301']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'augmented_assignment', 'children': ['303', '304'], 'value': '+='}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '304', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '305', 'type': 'elif_clause', 'children': ['306', '309']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': '=='}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'user_answer'}; {'id': '308', 'type': 'string', 'children': [], 'value': '"P"'}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'augmented_assignment', 'children': ['312', '313'], 'value': '-='}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'} | def _show_documentation(self):
documents = []
for key, document in self.app.documents.get().items():
if key != "main":
documents.append((key, document))
documents = sorted(documents, key=lambda x: x[0])
main = self.app.documents.get("main")
if main is not None:
documents.insert(0, (main.name, main))
user_answer = ""
index = 0
while user_answer != "X":
if index < 0:
index = 0
if index > len(documents) - 1:
index = len(documents) - 1
document = documents[index][1]
os.system('cls' if os.name == 'nt' else 'clear')
echo(Environment().from_string(document.content).render(app=self.app, plugin=document.plugin))
source = "This document is registered by '%s' under the name '%s'" % (document.plugin.name, document.name)
echo("-" * len(source))
echo(source)
echo("-" * len(source))
commands = "Actions: "
if index < len(documents) - 1:
commands += "[N]ext, "
if index > 0:
commands += "[P]revious, "
commands += "E[x]it"
echo(commands)
if index < len(documents) - 1:
default = "N"
elif index > 0:
default = "P"
else:
default = "X"
user_answer = prompt("Select your action", default=default).upper()
if user_answer == "N":
index += 1
elif user_answer == "P":
index -= 1 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_declared_from_conditions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'conds'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'namespace'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15', '26', '35', '44', '50', '54', '149', '160']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "''' like infer_declared except that it is passed a set of first party\n caveat conditions as a list of string rather than a set of macaroons.\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'conflicts'}; {'id': '14', 'type': 'list', 'children': [], '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': 'namespace'}; {'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': 'namespace'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Namespace'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'resolve'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'STD_NAMESPACE'}, {'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': 'string', 'children': [], 'value': "''"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'declared_cond'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'COND_DECLARED'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '53', 'type': 'dictionary', 'children': []}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cond'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'conds'}, {'id': '57', 'type': 'block', 'children': ['58', '80', '86', '96', '105', '117', '126', '143']}; {'id': '58', 'type': 'try_statement', 'children': ['59', '69']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'pattern_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'parse_caveat'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cond'}, {'id': '69', 'type': 'except_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '77', 'type': 'expression_list', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "''"}, {'id': '79', 'type': 'string', 'children': [], 'value': "''"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '!='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'declared_cond'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'continue_statement', 'children': []}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '103']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '!='}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'continue_statement', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '110']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '110', 'type': 'expression_list', 'children': ['111', '114']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'old_val'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '134']}, {'id': '127', 'type': 'boolean_operator', 'children': ['128', '131'], 'value': 'and'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'old_val'}; {'id': '130', 'type': 'None', 'children': []}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '!='}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'old_val'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '134', 'type': 'block', 'children': ['135', '142']}, {'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': 'conflicts'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '142', 'type': 'continue_statement', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '149', 'type': 'for_statement', 'children': ['150', '151', '155']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'conflicts'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'delete_statement', 'children': ['157']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '160', 'type': 'return_statement', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'info'} | def infer_declared_from_conditions(conds, namespace=None):
''' like infer_declared except that it is passed a set of first party
caveat conditions as a list of string rather than a set of macaroons.
'''
conflicts = []
if namespace is None:
namespace = Namespace()
prefix = namespace.resolve(STD_NAMESPACE)
if prefix is None:
prefix = ''
declared_cond = prefix + COND_DECLARED
info = {}
for cond in conds:
try:
name, rest = parse_caveat(cond)
except ValueError:
name, rest = '', ''
if name != declared_cond:
continue
parts = rest.split(' ', 1)
if len(parts) != 2:
continue
key, val = parts[0], parts[1]
old_val = info.get(key)
if old_val is not None and old_val != val:
conflicts.append(key)
continue
info[key] = val
for key in set(conflicts):
del info[key]
return info |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cited_dois'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '5', 'type': 'block', 'children': ['6', '27', '31', '35', '119', '200']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13', '21']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'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': 'file'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'plaintext_citations'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_plaintext_citations'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'plaintext_citations'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dois'}; {'id': '30', 'type': 'dictionary', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'crossref_queue'}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'citation'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'plaintext_citations'}, {'id': '39', 'type': 'slice', 'children': ['40']}; {'id': '40', 'type': 'colon', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42', '51', '72', '81', '107']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'matched_dois'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'extract_from_text'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'citation'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '58']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '57'], 'value': '>'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'matched_dois'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'block', 'children': ['59', '71']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dois'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'citation'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'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': 'matched_dois'}, {'id': '71', 'type': 'continue_statement', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'matched_arxiv'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'arxiv'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'extract_from_text'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'citation'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '88']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '87'], 'value': '>'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'matched_arxiv'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'block', 'children': ['89', '106']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dois'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'citation'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'arxiv'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'to_doi'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'matched_arxiv'}; {'id': '106', 'type': 'continue_statement', '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': 'crossref_queue'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'remove_urls'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'citation'}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '128']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'crossref_queue'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'CROSSREF_MAX_BATCH_SIZE'}; {'id': '128', 'type': 'block', 'children': ['129', '137']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'batch'}; {'id': '132', 'type': 'list_comprehension', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '137', 'type': 'try_statement', 'children': ['138', '184']}; {'id': '138', 'type': 'block', 'children': ['139', '151']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'CROSSREF_LINKS_API_URL'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '151', 'type': 'for_statement', 'children': ['152', '153', '160']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '153', 'type': 'subscript', 'children': ['154', '159']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'string', 'children': [], 'value': '"results"'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'try_statement', 'children': ['162', '173']}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '170']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dois'}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '169', 'type': 'string', 'children': [], 'value': '"text"'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '172', 'type': 'string', 'children': [], 'value': '"doi"'}, {'id': '173', 'type': 'except_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'dois'}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"text"'}, {'id': '183', 'type': 'None', 'children': []}; {'id': '184', 'type': 'except_clause', 'children': ['185', '189']}, {'id': '185', 'type': 'tuple', 'children': ['186', '187', '188']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'RequestException'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'for_statement', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'batch'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '199']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dois'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '199', 'type': 'None', 'children': []}; {'id': '200', 'type': 'return_statement', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'dois'} | def get_cited_dois(file):
if not isinstance(file, list):
plaintext_citations = get_plaintext_citations(file)
else:
plaintext_citations = file
dois = {}
crossref_queue = []
for citation in plaintext_citations[:]:
matched_dois = doi.extract_from_text(citation)
if len(matched_dois) > 0:
dois[citation] = next(iter(matched_dois))
continue
matched_arxiv = arxiv.extract_from_text(citation)
if len(matched_arxiv) > 0:
dois[citation] = arxiv.to_doi(next(iter(matched_arxiv)))
continue
crossref_queue.append(tools.remove_urls(citation))
for batch in tools.batch(crossref_queue, CROSSREF_MAX_BATCH_SIZE):
batch = [i for i in batch]
try:
request = requests.post(CROSSREF_LINKS_API_URL, json=batch)
for result in request.json()["results"]:
try:
dois[result["text"]] = result["doi"]
except KeyError:
dois[result["text"]] = None
except (RequestException, ValueError, KeyError):
for i in batch:
dois[i] = None
return dois |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'used_args'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '87', '96']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '24']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'subscript', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'colon', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '34', '48', '57']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'continue_statement', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'option_str'}, {'id': '37', 'type': 'subscript', 'children': ['38', '45']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '42', 'type': 'slice', 'children': ['43', '44']}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'colon', 'children': []}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '-'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_option'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'option_str'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '66']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '62'], 'value': 'or'}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'need_value'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'tuple', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '=='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'document'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_word_before_cursor'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'WORD'}; {'id': '86', 'type': 'True', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"Found args values %s"'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '107']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '98', 'type': 'call', 'children': ['99', '106']}, {'id': '99', 'type': 'attribute', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '106', 'type': 'argument_list', 'children': []}, {'id': '107', 'type': 'block', 'children': ['108', '114']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '111']}, {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '126']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'is_multiple'}; {'id': '118', 'type': 'block', 'children': ['119', '123']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '122', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'yield', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '126', 'type': 'elif_clause', 'children': ['127', '135']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '134'], 'value': 'is'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'for_statement', 'children': ['137', '138', '144']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'nargs'}; {'id': '144', 'type': 'block', 'children': ['145', '154', '164']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '160']}, {'id': '155', 'type': 'comparison_operator', 'children': ['156', '159'], 'value': 'is'}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'False', 'children': []}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'yield', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '167']}, {'id': '165', 'type': 'not_operator', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'raise_statement', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'StopIteration'} | def used_args(self):
values = []
for idx, c in enumerate(self.words[1:]):
if c.startswith('-'):
continue
option_str = self.words[1:][idx - 1]
option = self.get_option(option_str)
if option is None or not option.need_value:
values.append((c, c == self.document.get_word_before_cursor(WORD=True)))
logger.debug("Found args values %s" % values)
for arg in self.cmd.args.values():
if not values:
raise StopIteration
if arg.is_multiple:
values = []
yield arg
elif type(arg.nargs) is int:
for _ in range(arg.nargs):
value = values.pop(0)
if value[1] is False:
yield arg
if not values:
raise StopIteration |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_preprocess'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '28', '39', '50', '61', '72', '83', '94', '105', '116', '127', '138', '149', '333']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'string', 'children': [], 'value': "r'(\\b)a(\\b)'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "r'\\g<1>one\\g<2>'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'string', 'children': [], 'value': "r'to the (.*) power'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "r'to \\g<1>'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'string', 'children': [], 'value': "r'to the (.*?)(\\b)'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "r'to \\g<1>\\g<2>'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'string', 'children': [], 'value': "r'log of'"}; {'id': '48', 'type': 'string', 'children': [], 'value': "r'log'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'string', 'children': [], 'value': "r'(square )?root( of)?'"}, {'id': '59', 'type': 'string', 'children': [], 'value': "r'sqrt'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'string', 'children': [], 'value': "r'squared'"}; {'id': '70', 'type': 'string', 'children': [], 'value': "r'to two'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'string', 'children': [], 'value': "r'cubed'"}, {'id': '81', 'type': 'string', 'children': [], 'value': "r'to three'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'string', 'children': [], 'value': "r'divided?( by)?'"}; {'id': '92', 'type': 'string', 'children': [], 'value': "r'divide'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'string', 'children': [], 'value': "r'(\\b)over(\\b)'"}, {'id': '103', 'type': 'string', 'children': [], 'value': "r'\\g<1>divide\\g<2>'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']}, {'id': '113', 'type': 'string', 'children': [], 'value': "r'(\\b)EE(\\b)'"}; {'id': '114', 'type': 'string', 'children': [], 'value': "r'\\g<1>e\\g<2>'"}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'string', 'children': [], 'value': "r'(\\b)E(\\b)'"}, {'id': '125', 'type': 'string', 'children': [], 'value': "r'\\g<1>e\\g<2>'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'string', 'children': [], 'value': "r'(\\b)pie(\\b)'"}; {'id': '136', 'type': 'string', 'children': [], 'value': "r'\\g<1>pi\\g<2>'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'string', 'children': [], 'value': "r'(\\b)PI(\\b)'"}, {'id': '147', 'type': 'string', 'children': [], 'value': "r'\\g<1>pi\\g<2>'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '149', 'type': 'function_definition', 'children': ['150', '151', '153']}; {'id': '150', 'type': 'function_name', 'children': [], 'value': 'findImplicitMultiplications'}, {'id': '151', 'type': 'parameters', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '153', 'type': 'block', 'children': ['154', '232', '325']}; {'id': '154', 'type': 'function_definition', 'children': ['155', '156', '158']}, {'id': '155', 'type': 'function_name', 'children': [], 'value': 'findConstantMultiplications'}; {'id': '156', 'type': 'parameters', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '158', 'type': 'block', 'children': ['159', '168', '172', '178', '230']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '171', 'type': 'string', 'children': [], 'value': '""'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'NumberService'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'for_statement', 'children': ['179', '182', '186']}, {'id': '179', 'type': 'pattern_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '186', 'type': 'block', 'children': ['187', '214']}, {'id': '187', 'type': 'if_statement', 'children': ['188', '197']}; {'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': 'i'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'in'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'MathService'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '__constants__'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'if_statement', 'children': ['199', '209']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'isValid'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '-'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'augmented_assignment', 'children': ['212', '213'], 'value': '+='}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '213', 'type': 'string', 'children': [], 'value': '" times"'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '217', '222']}, {'id': '215', 'type': 'not_operator', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '222', 'type': 'else_clause', 'children': ['223']}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'augmented_assignment', 'children': ['226', '227'], 'value': '+='}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'}; {'id': '228', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '230', 'type': 'return_statement', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '232', 'type': 'function_definition', 'children': ['233', '234', '236']}, {'id': '233', 'type': 'function_name', 'children': [], 'value': 'findUnaryMultiplications'}; {'id': '234', 'type': 'parameters', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '236', 'type': 'block', 'children': ['237', '246', '250', '323']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '249', 'type': 'string', 'children': [], 'value': '""'}; {'id': '250', 'type': 'for_statement', 'children': ['251', '254', '258']}, {'id': '251', 'type': 'pattern_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '258', 'type': 'block', 'children': ['259', '307']}, {'id': '259', 'type': 'if_statement', 'children': ['260', '269']}; {'id': '260', 'type': 'boolean_operator', 'children': ['261', '264'], 'value': 'and'}, {'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': '>'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '263', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': 'in'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'MathService'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': '__unaryOperators__'}, {'id': '269', 'type': 'block', 'children': ['270', '278', '286', '294']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'last_op'}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '-'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'binary'}, {'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'in'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'last_op'}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'MathService'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': '__binaryOperators__'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'unary'}, {'id': '289', 'type': 'comparison_operator', 'children': ['290', '291'], 'value': 'in'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'last_op'}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'MathService'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': '__unaryOperators__'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '302']}, {'id': '295', 'type': 'boolean_operator', 'children': ['296', '297'], 'value': 'and'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'last_op'}, {'id': '297', 'type': 'not_operator', 'children': ['298']}; {'id': '298', 'type': 'parenthesized_expression', 'children': ['299'], 'value': '()'}, {'id': '299', 'type': 'boolean_operator', 'children': ['300', '301'], 'value': 'or'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'binary'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'unary'}; {'id': '302', 'type': 'block', 'children': ['303']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'augmented_assignment', 'children': ['305', '306'], 'value': '+='}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '306', 'type': 'string', 'children': [], 'value': '" times"'}, {'id': '307', 'type': 'if_statement', 'children': ['308', '310', '315']}; {'id': '308', 'type': 'not_operator', 'children': ['309']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'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': 'revision'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '315', 'type': 'else_clause', 'children': ['316']}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'augmented_assignment', 'children': ['319', '320'], 'value': '+='}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '+'}, {'id': '321', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '323', 'type': 'return_statement', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'revision'}, {'id': '325', 'type': 'return_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'findUnaryMultiplications'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'findConstantMultiplications'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '333', 'type': 'return_statement', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'findImplicitMultiplications'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'inp'} | def _preprocess(inp):
inp = re.sub(r'(\b)a(\b)', r'\g<1>one\g<2>', inp)
inp = re.sub(r'to the (.*) power', r'to \g<1>', inp)
inp = re.sub(r'to the (.*?)(\b)', r'to \g<1>\g<2>', inp)
inp = re.sub(r'log of', r'log', inp)
inp = re.sub(r'(square )?root( of)?', r'sqrt', inp)
inp = re.sub(r'squared', r'to two', inp)
inp = re.sub(r'cubed', r'to three', inp)
inp = re.sub(r'divided?( by)?', r'divide', inp)
inp = re.sub(r'(\b)over(\b)', r'\g<1>divide\g<2>', inp)
inp = re.sub(r'(\b)EE(\b)', r'\g<1>e\g<2>', inp)
inp = re.sub(r'(\b)E(\b)', r'\g<1>e\g<2>', inp)
inp = re.sub(r'(\b)pie(\b)', r'\g<1>pi\g<2>', inp)
inp = re.sub(r'(\b)PI(\b)', r'\g<1>pi\g<2>', inp)
def findImplicitMultiplications(inp):
def findConstantMultiplications(inp):
split = inp.split(' ')
revision = ""
converter = NumberService()
for i, w in enumerate(split):
if i > 0 and w in MathService.__constants__:
if converter.isValid(split[i - 1]):
revision += " times"
if not revision:
revision = w
else:
revision += " " + w
return revision
def findUnaryMultiplications(inp):
split = inp.split(' ')
revision = ""
for i, w in enumerate(split):
if i > 0 and w in MathService.__unaryOperators__:
last_op = split[i - 1]
binary = last_op in MathService.__binaryOperators__
unary = last_op in MathService.__unaryOperators__
if last_op and not (binary or unary):
revision += " times"
if not revision:
revision = w
else:
revision += " " + w
return revision
return findUnaryMultiplications(findConstantMultiplications(inp))
return findImplicitMultiplications(inp) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parseEquation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '25', '106', '233', '242']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'MathService'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_preprocess'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '25', 'type': 'for_statement', 'children': ['26', '29', '33']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '40']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '__unaryOperators__'}; {'id': '40', 'type': 'block', 'children': ['41', '49', '62', '77', '92']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '__unaryOperators__'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'eq1'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '59', 'type': 'slice', 'children': ['60', '61']}; {'id': '60', 'type': 'colon', 'children': []}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'eq2'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '72', 'type': 'slice', 'children': ['73', '76']}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'colon', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'MathService'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_applyUnary'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '91']}, {'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': 'parseEquation'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'eq2'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'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': 'parseEquation'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '+'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'eq1'}, {'id': '101', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '106', 'type': 'function_definition', 'children': ['107', '108', '110']}, {'id': '107', 'type': 'function_name', 'children': [], 'value': 'extractNumbersAndSymbols'}; {'id': '108', 'type': 'parameters', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '110', 'type': 'block', 'children': ['111', '115', '119', '123', '177', '187', '218', '229']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'numbers'}; {'id': '114', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'symbols'}; {'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': 'next_number'}; {'id': '122', 'type': 'string', 'children': [], 'value': '""'}, {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '131']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138', '164']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '__binaryOperators__'}; {'id': '138', 'type': 'block', 'children': ['139', '150']}, {'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': 'symbols'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '__binaryOperators__'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'next_number'}; {'id': '152', 'type': 'block', 'children': ['153', '160']}, {'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': 'numbers'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'next_number'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'next_number'}, {'id': '163', 'type': 'string', 'children': [], 'value': '""'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166', '173']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'next_number'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'augmented_assignment', 'children': ['171', '172'], 'value': '+='}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'next_number'}; {'id': '172', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'augmented_assignment', 'children': ['175', '176'], 'value': '+='}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'next_number'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'next_number'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'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': 'numbers'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'next_number'}, {'id': '187', 'type': 'function_definition', 'children': ['188', '189', '191']}; {'id': '188', 'type': 'function_name', 'children': [], 'value': 'convert'}, {'id': '189', 'type': 'parameters', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '191', 'type': 'block', 'children': ['192', '205', '211']}; {'id': '192', 'type': 'if_statement', 'children': ['193', '198']}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'in'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '__constants__'}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'return_statement', 'children': ['200']}; {'id': '200', 'type': 'subscript', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': '__constants__'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'NumberService'}; {'id': '210', 'type': 'argument_list', 'children': []}, {'id': '211', 'type': 'return_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '221', 'type': 'list_comprehension', 'children': ['222', '226']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'convert'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '229', 'type': 'return_statement', 'children': ['230']}; {'id': '230', 'type': 'expression_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'numbers'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'symbols'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '238']}, {'id': '235', 'type': 'pattern_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'symbols'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'extractNumbersAndSymbols'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '242', 'type': 'return_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'MathService'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': '_calculate'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'symbols'} | def parseEquation(self, inp):
inp = MathService._preprocess(inp)
split = inp.split(' ')
for i, w in enumerate(split):
if w in self.__unaryOperators__:
op = self.__unaryOperators__[w]
eq1 = ' '.join(split[:i])
eq2 = ' '.join(split[i + 1:])
result = MathService._applyUnary(self.parseEquation(eq2), op)
return self.parseEquation(eq1 + " " + str(result))
def extractNumbersAndSymbols(inp):
numbers = []
symbols = []
next_number = ""
for w in inp.split(' '):
if w in self.__binaryOperators__:
symbols.append(self.__binaryOperators__[w])
if next_number:
numbers.append(next_number)
next_number = ""
else:
if next_number:
next_number += " "
next_number += w
if next_number:
numbers.append(next_number)
def convert(n):
if n in self.__constants__:
return self.__constants__[n]
converter = NumberService()
return converter.parse(n)
numbers = [convert(n) for n in numbers]
return numbers, symbols
numbers, symbols = extractNumbersAndSymbols(inp)
return MathService._calculate(numbers, symbols) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'activate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'plugins'}, {'id': '7', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '36', '52', '56', '286']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_log'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"Plugins Activation started"'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '25']}, {'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': 'plugins'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'raise_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"plugins must be a list, not %s"'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'plugins'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'}, {'id': '45', 'type': 'string', 'children': [], 'value': '"Plugins to activate: %s"'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'plugins'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'plugins_activated'}, {'id': '55', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'plugins'}, {'id': '59', 'type': 'block', 'children': ['60', '78', '179']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '67']}, {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'raise_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'}, {'id': '73', 'type': 'string', 'children': [], 'value': '"plugin name must be a str, not %s"'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '100']}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '89'], 'value': 'and'}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'not'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_plugins'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '88', 'type': 'argument_list', 'children': []}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'id': '91', 'type': 'call', 'children': ['92', '99']}; {'id': '92', 'type': 'attribute', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'classes'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_classes'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'block', 'children': ['101', '110']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '108']}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_log'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': '"Initialisation needed before activation."'}; {'id': '110', 'type': 'try_statement', 'children': ['111', '120']}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'initialise_by_names'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'list', 'children': ['119'], 'value': '[plugin_name]'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '120', 'type': 'except_clause', 'children': ['121', '125']}, {'id': '121', 'type': 'as_pattern', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '123', 'type': 'as_pattern_target', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '125', 'type': 'block', 'children': ['126', '139']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '%'}, {'id': '135', 'type': 'string', 'children': [], 'value': '"Couldn\'t initialise plugin %s. Reason %s"'}; {'id': '136', 'type': 'tuple', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '145', '176']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '145', 'type': 'block', 'children': ['146', '152', '167']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"Couldn\'t initialise plugin %s"'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '160']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '159'], 'value': '<'}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'augmented_assignment', 'children': ['163', '164'], 'value': '+='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'}, {'id': '165', 'type': 'string', 'children': [], 'value': '"Reason: %s"'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'raise_from'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '175']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '176', 'type': 'else_clause', 'children': ['177']}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'continue_statement', 'children': []}, {'id': '179', 'type': 'if_statement', 'children': ['180', '189']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'in'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '182', 'type': 'call', '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': '_plugins'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '188', 'type': 'argument_list', 'children': []}, {'id': '189', 'type': 'block', 'children': ['190', '201']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '%'}, {'id': '199', 'type': 'string', 'children': [], 'value': '"Activating plugin %s"'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'id': '201', 'type': 'if_statement', 'children': ['202', '210', '262']}; {'id': '202', 'type': 'not_operator', 'children': ['203']}, {'id': '203', 'type': 'attribute', 'children': ['204', '209']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': '_plugins'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'active'}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'try_statement', 'children': ['212', '223', '242']}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '222']}, {'id': '215', 'type': 'attribute', 'children': ['216', '221']}; {'id': '216', 'type': 'subscript', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_plugins'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'activate'}; {'id': '222', 'type': 'argument_list', 'children': []}, {'id': '223', 'type': 'except_clause', 'children': ['224', '228']}; {'id': '224', 'type': 'as_pattern', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '226', 'type': 'as_pattern_target', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'raise_from'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '241']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'PluginNotActivatableException'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '%'}, {'id': '237', 'type': 'string', 'children': [], 'value': '"Plugin %s could not be activated: %s"'}; {'id': '238', 'type': 'tuple', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '242', 'type': 'else_clause', 'children': ['243']}, {'id': '243', 'type': 'block', 'children': ['244', '255']}; {'id': '244', 'type': 'expression_statement', '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': '_log'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '%'}, {'id': '253', 'type': 'string', 'children': [], 'value': '"Plugin %s activated"'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'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': 'plugins_activated'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264', '275']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '271']}; {'id': '266', 'type': 'attribute', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'}, {'id': '273', 'type': 'string', 'children': [], 'value': '"Plugin %s got already activated."'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'plugin_name'}, {'id': '275', 'type': 'if_statement', 'children': ['276', '281']}; {'id': '276', 'type': 'attribute', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'strict'}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'raise_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'PluginNotInitialisableException'}, {'id': '285', 'type': 'argument_list', 'children': []}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'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': 'self'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'}, {'id': '295', 'type': 'string', 'children': [], 'value': '"Plugins activated: %s"'}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'plugins_activated'} | def activate(self, plugins=[]):
self._log.debug("Plugins Activation started")
if not isinstance(plugins, list):
raise AttributeError("plugins must be a list, not %s" % type(plugins))
self._log.debug("Plugins to activate: %s" % ", ".join(plugins))
plugins_activated = []
for plugin_name in plugins:
if not isinstance(plugin_name, str):
raise AttributeError("plugin name must be a str, not %s" % type(plugin_name))
if plugin_name not in self._plugins.keys() and plugin_name in self.classes._classes.keys():
self._log.debug("Initialisation needed before activation.")
try:
self.initialise_by_names([plugin_name])
except Exception as e:
self._log.error("Couldn't initialise plugin %s. Reason %s" % (plugin_name, e))
if self._app.strict:
error = "Couldn't initialise plugin %s" % plugin_name
if sys.version_info[0] < 3:
error += "Reason: %s" % e
raise_from(Exception(error), e)
else:
continue
if plugin_name in self._plugins.keys():
self._log.debug("Activating plugin %s" % plugin_name)
if not self._plugins[plugin_name].active:
try:
self._plugins[plugin_name].activate()
except Exception as e:
raise_from(
PluginNotActivatableException("Plugin %s could not be activated: %s" % (plugin_name,
e)), e)
else:
self._log.debug("Plugin %s activated" % plugin_name)
plugins_activated.append(plugin_name)
else:
self._log.warning("Plugin %s got already activated." % plugin_name)
if self._app.strict:
raise PluginNotInitialisableException()
self._log.info("Plugins activated: %s" % ", ".join(plugins_activated)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dispersion_ranking_NN'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nnm'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'num_norm_avg'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '50'}, {'id': '9', 'type': 'block', 'children': ['10', '17', '27', '41', '52', '70', '84', '102', '110', '128', '138']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'knn_avg'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nnm'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'D_avg'}; {'id': '20', 'type': 'subscript', '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': 'adata'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'X_knn_avg'"}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'pattern_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'mu'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mean_variance_axis'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'D_avg'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '59']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '>'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'mu'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '65'], 'value': '/'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '>'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mu'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'mu'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '>'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mu'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '79']}; {'id': '72', 'type': 'subscript', 'children': ['73', '78']}, {'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': 'adata'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'spatial_dispersions'"}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'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': 'ma'}, {'id': '87', 'type': 'call', 'children': ['88', '101']}; {'id': '88', 'type': 'attribute', 'children': ['89', '100']}, {'id': '89', 'type': 'subscript', 'children': ['90', '96']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '96', 'type': 'slice', 'children': ['97', '99']}, {'id': '97', 'type': 'unary_operator', 'children': ['98'], 'value': '-'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'num_norm_avg'}, {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '109']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '>='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ma'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ma'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '113', 'type': 'call', 'children': ['114', '127']}; {'id': '114', 'type': 'attribute', 'children': ['115', '126']}, {'id': '115', 'type': 'parenthesized_expression', 'children': ['116'], 'value': '()'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '125'], 'value': '**'}, {'id': '117', 'type': 'parenthesized_expression', 'children': ['118'], 'value': '()'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '/'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dispersions'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dispersions'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '127', 'type': 'argument_list', 'children': []}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '137']}; {'id': '130', 'type': 'subscript', 'children': ['131', '136']}, {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'adata'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'weights'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '138', 'type': 'return_statement', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'weights'} | def dispersion_ranking_NN(self, nnm, num_norm_avg=50):
self.knn_avg(nnm)
D_avg = self.adata.layers['X_knn_avg']
mu, var = sf.mean_variance_axis(D_avg, axis=0)
dispersions = np.zeros(var.size)
dispersions[mu > 0] = var[mu > 0] / mu[mu > 0]
self.adata.var['spatial_dispersions'] = dispersions.copy()
ma = np.sort(dispersions)[-num_norm_avg:].mean()
dispersions[dispersions >= ma] = ma
weights = ((dispersions / dispersions.max())**0.5).flatten()
self.adata.var['weights'] = weights
return weights |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scatter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'projection'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'rainbow'"}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'linewidth'}; {'id': '16', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'k'"}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'colorbar'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '29', 'type': 'dictionary_splat_pattern', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36', '42']}, {'id': '33', 'type': 'parenthesized_expression', 'children': ['34'], 'value': '()'}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'PLOTTING'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'string', 'children': [], 'value': '"matplotlib not installed!"'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'id': '43', 'type': 'block', 'children': ['44', '124', '144']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '51', '74', '118']}, {'id': '45', 'type': 'parenthesized_expression', 'children': ['46'], 'value': '()'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'try_statement', 'children': ['53', '64']}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '57', 'type': 'subscript', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'adata'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'obsm'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '64', 'type': 'except_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'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': 'concatenated_string', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'Please create a projection first using run_umap or'"}, {'id': '73', 'type': 'string', 'children': [], 'value': "'run_tsne'"}; {'id': '74', 'type': 'elif_clause', 'children': ['75', '79']}, {'id': '75', 'type': 'parenthesized_expression', 'children': ['76'], 'value': '()'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'try_statement', 'children': ['81', '92']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '85', 'type': 'subscript', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'adata'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'obsm'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'X_umap'"}; {'id': '92', 'type': 'except_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'try_statement', 'children': ['96', '107']}; {'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': 'dt'}; {'id': '100', 'type': 'subscript', 'children': ['101', '106']}, {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'adata'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'obsm'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'X_tsne'"}, {'id': '107', 'type': 'except_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '109', 'type': 'block', 'children': ['110', '117']}; {'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': 'concatenated_string', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"Please create either a t-SNE or UMAP projection"'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"first."'}, {'id': '117', 'type': 'return_statement', 'children': []}; {'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': 'dt'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '129']}, {'id': '125', 'type': 'parenthesized_expression', 'children': ['126'], 'value': '()'}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'block', 'children': ['130', '136']}; {'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': 'plt'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'figure'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'gca'}, {'id': '143', 'type': 'argument_list', 'children': []}; {'id': '144', 'type': 'if_statement', 'children': ['145', '149', '177']}, {'id': '145', 'type': 'parenthesized_expression', 'children': ['146'], 'value': '()'}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'is'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '148', 'type': 'None', 'children': []}, {'id': '149', 'type': 'block', 'children': ['150']}; {'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': 'plt'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '161', '166', '169', '172', '175']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158', '160']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '158', 'type': 'slice', 'children': ['159']}, {'id': '159', 'type': 'colon', 'children': []}; {'id': '160', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163', '165']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '163', 'type': 'slice', 'children': ['164']}; {'id': '164', 'type': 'colon', 'children': []}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'linewidth'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'linewidth'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}, {'id': '175', 'type': 'dictionary_splat', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179', '207']}, {'id': '179', 'type': 'if_statement', 'children': ['180', '185']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'try_statement', 'children': ['187', '202']}, {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '191', 'type': 'call', 'children': ['192', '201']}; {'id': '192', 'type': 'attribute', 'children': ['193', '200']}, {'id': '193', 'type': 'subscript', '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': 'adata'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'obs'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'get_values'}, {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'except_clause', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '207', 'type': 'if_statement', 'children': ['208', '242', '331']}; {'id': '208', 'type': 'parenthesized_expression', 'children': ['209'], 'value': '()'}, {'id': '209', 'type': 'boolean_operator', 'children': ['210', '228'], 'value': 'and'}; {'id': '210', 'type': 'parenthesized_expression', 'children': ['211'], 'value': '()'}, {'id': '211', 'type': 'boolean_operator', 'children': ['212', '219'], 'value': 'or'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '218']}, {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '217', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'str_'}; {'id': '228', 'type': 'parenthesized_expression', 'children': ['229'], 'value': '()'}, {'id': '229', 'type': 'boolean_operator', 'children': ['230', '237'], 'value': 'or'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ndarray'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '242', 'type': 'block', 'children': ['243', '252', '266', '301']}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ut'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'convert_annotations'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '257']}; {'id': '254', 'type': 'pattern_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'ai'}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '263', 'type': 'keyword_argument', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'return_index'}, {'id': '265', 'type': 'True', 'children': []}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'cax'}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '273', 'type': 'argument_list', 'children': ['274', '279', '284', '287', '290', '293', '296', '299']}; {'id': '274', 'type': 'subscript', 'children': ['275', '276', '278']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '276', 'type': 'slice', 'children': ['277']}, {'id': '277', 'type': 'colon', 'children': []}; {'id': '278', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '279', 'type': 'subscript', 'children': ['280', '281', '283']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '281', 'type': 'slice', 'children': ['282']}; {'id': '282', 'type': 'colon', 'children': []}, {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'linewidth'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'linewidth'}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}, {'id': '299', 'type': 'dictionary_splat', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '301', 'type': 'if_statement', 'children': ['302', '304']}; {'id': '302', 'type': 'parenthesized_expression', 'children': ['303'], 'value': '()'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'colorbar'}; {'id': '304', 'type': 'block', 'children': ['305', '320']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'cbar'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'colorbar'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '314', '317']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'cax'}; {'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '327']}; {'id': '322', 'type': 'attribute', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'cbar'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'ai'}, {'id': '331', 'type': 'else_clause', 'children': ['332']}; {'id': '332', 'type': 'block', 'children': ['333', '354', '358', '393']}, {'id': '333', 'type': 'if_statement', 'children': ['334', '349']}; {'id': '334', 'type': 'not_operator', 'children': ['335']}, {'id': '335', 'type': 'parenthesized_expression', 'children': ['336'], 'value': '()'}; {'id': '336', 'type': 'boolean_operator', 'children': ['337', '344'], 'value': 'or'}, {'id': '337', 'type': 'call', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '339', 'type': 'argument_list', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '344', 'type': 'call', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '346', 'type': 'argument_list', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '349', 'type': 'block', 'children': ['350']}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'assignment', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'colorbar'}, {'id': '353', 'type': 'False', 'children': []}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'assignment', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'cax'}, {'id': '361', 'type': 'call', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '365', 'type': 'argument_list', 'children': ['366', '371', '376', '379', '382', '385', '388', '391']}; {'id': '366', 'type': 'subscript', 'children': ['367', '368', '370']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '368', 'type': 'slice', 'children': ['369']}, {'id': '369', 'type': 'colon', 'children': []}; {'id': '370', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '371', 'type': 'subscript', 'children': ['372', '373', '375']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '373', 'type': 'slice', 'children': ['374']}; {'id': '374', 'type': 'colon', 'children': []}, {'id': '375', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '376', 'type': 'keyword_argument', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '379', 'type': 'keyword_argument', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '385', 'type': 'keyword_argument', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'linewidth'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'linewidth'}; {'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'edgecolor'}, {'id': '391', 'type': 'dictionary_splat', 'children': ['392']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '393', 'type': 'if_statement', 'children': ['394', '396']}; {'id': '394', 'type': 'parenthesized_expression', 'children': ['395'], 'value': '()'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'colorbar'}; {'id': '396', 'type': 'block', 'children': ['397']}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'call', 'children': ['399', '402']}, {'id': '399', 'type': 'attribute', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'colorbar'}; {'id': '402', 'type': 'argument_list', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'cax'}; {'id': '404', 'type': 'keyword_argument', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'ax'} | def scatter(self, projection=None, c=None, cmap='rainbow', linewidth=0.0,
edgecolor='k', axes=None, colorbar=True, s=10, **kwargs):
if (not PLOTTING):
print("matplotlib not installed!")
else:
if(isinstance(projection, str)):
try:
dt = self.adata.obsm[projection]
except KeyError:
print('Please create a projection first using run_umap or'
'run_tsne')
elif(projection is None):
try:
dt = self.adata.obsm['X_umap']
except KeyError:
try:
dt = self.adata.obsm['X_tsne']
except KeyError:
print("Please create either a t-SNE or UMAP projection"
"first.")
return
else:
dt = projection
if(axes is None):
plt.figure()
axes = plt.gca()
if(c is None):
plt.scatter(dt[:, 0], dt[:, 1], s=s,
linewidth=linewidth, edgecolor=edgecolor, **kwargs)
else:
if isinstance(c, str):
try:
c = self.adata.obs[c].get_values()
except KeyError:
0
if((isinstance(c[0], str) or isinstance(c[0], np.str_)) and
(isinstance(c, np.ndarray) or isinstance(c, list))):
i = ut.convert_annotations(c)
ui, ai = np.unique(i, return_index=True)
cax = axes.scatter(dt[:,0], dt[:,1], c=i, cmap=cmap, s=s,
linewidth=linewidth,
edgecolor=edgecolor,
**kwargs)
if(colorbar):
cbar = plt.colorbar(cax, ax=axes, ticks=ui)
cbar.ax.set_yticklabels(c[ai])
else:
if not (isinstance(c, np.ndarray) or isinstance(c, list)):
colorbar = False
i = c
cax = axes.scatter(dt[:,0], dt[:,1], c=i, cmap=cmap, s=s,
linewidth=linewidth,
edgecolor=edgecolor,
**kwargs)
if(colorbar):
plt.colorbar(cax, ax=axes) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parseFloat'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '6', 'type': 'block', 'children': ['7', '86', '236', '243', '248', '255', '260']}, {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'pointFloat'}, {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '11', 'type': 'block', 'children': ['12', '22', '84']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "r'(.*) point (.*)'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '24', 'type': 'block', 'children': ['25', '34', '43', '47', '51', '75']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'whole'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '46', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'coeff'}; {'id': '50', 'type': 'float', 'children': [], 'value': '0.10'}, {'id': '51', 'type': 'for_statement', 'children': ['52', '53', '59']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'digit'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'frac'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '59', 'type': 'block', 'children': ['60', '71']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'total'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '*'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'coeff'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'digit'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'augmented_assignment', 'children': ['73', '74'], 'value': '/='}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'coeff'}; {'id': '74', 'type': 'float', 'children': [], 'value': '10.0'}, {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '83'], 'value': '+'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'parseInt'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'whole'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'function_definition', 'children': ['87', '88', '90']}, {'id': '87', 'type': 'function_name', 'children': [], 'value': 'fractionFloat'}; {'id': '88', 'type': 'parameters', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '90', 'type': 'block', 'children': ['91', '101', '234']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': "r'(.*) and (.*)'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '101', 'type': 'if_statement', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '103', 'type': 'block', 'children': ['104', '118', '127', '138', '149', '158', '166', '174']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'whole'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'parseInt'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'frac'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'string', 'children': [], 'value': "r'(\\w+)s(\\b)'"}; {'id': '136', 'type': 'string', 'children': [], 'value': "'\\g<1>\\g<2>'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'frac'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'string', 'children': [], 'value': "r'(\\b)a(\\b)'"}, {'id': '147', 'type': 'string', 'children': [], 'value': "'\\g<1>one\\g<2>'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '163', 'type': 'slice', 'children': ['164', '165']}; {'id': '164', 'type': 'colon', 'children': []}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '171', 'type': 'slice', 'children': ['172', '173']}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '173', 'type': 'colon', 'children': []}; {'id': '174', 'type': 'while_statement', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'try_statement', 'children': ['178', '216']}; {'id': '178', 'type': 'block', 'children': ['179', '193', '207']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'num_value'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'denom_value'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '+'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'whole'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '215'], 'value': '/'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'num_value'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'denom_value'}; {'id': '216', 'type': 'except_clause', 'children': ['217']}, {'id': '217', 'type': 'block', 'children': ['218', '226']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'augmented_assignment', 'children': ['220', '221'], 'value': '+='}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '223', 'type': 'slice', 'children': ['224', '225']}; {'id': '224', 'type': 'colon', 'children': []}, {'id': '225', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '231', 'type': 'slice', 'children': ['232', '233']}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'colon', 'children': []}; {'id': '234', 'type': 'return_statement', 'children': ['235']}, {'id': '235', 'type': 'None', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'pointFloat'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '243', 'type': 'if_statement', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'return_statement', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'fractionFloat'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'return_statement', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '260', 'type': 'return_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'parseInt'}, {'id': '265', 'type': 'argument_list', 'children': ['266']} | def parseFloat(self, words):
def pointFloat(words):
m = re.search(r'(.*) point (.*)', words)
if m:
whole = m.group(1)
frac = m.group(2)
total = 0.0
coeff = 0.10
for digit in frac.split(' '):
total += coeff * self.parse(digit)
coeff /= 10.0
return self.parseInt(whole) + total
return None
def fractionFloat(words):
m = re.search(r'(.*) and (.*)', words)
if m:
whole = self.parseInt(m.group(1))
frac = m.group(2)
frac = re.sub(r'(\w+)s(\b)', '\g<1>\g<2>', frac)
frac = re.sub(r'(\b)a(\b)', '\g<1>one\g<2>', frac)
split = frac.split(' ')
num = split[:1]
denom = split[1:]
while denom:
try:
num_value = self.parse(' '.join(num))
denom_value = self.parse(' '.join(denom))
return whole + float(num_value) / denom_value
except:
num += denom[:1]
denom = denom[1:]
return None
result = pointFloat(words)
if result:
return result
result = fractionFloat(words)
if result:
return result
return self.parseInt(words) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'marshal_output'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'block', 'children': ['15', '19', '34', '50', '60', '74', '78', '87', '91', '114', '143', '160', '312', '323']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'list', 'children': ['23', '26', '27', '30', '31'], 'value': '[self._executable, "-u", self._user, "-p", self._port]'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_executable'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"-u"'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_user'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"-p"'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_port'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'augmented_assignment', 'children': ['41', '42'], 'value': '+='}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '42', 'type': 'list', 'children': ['43', '44'], 'value': '["-c", str(self._client)]'}, {'id': '43', 'type': 'string', 'children': [], 'value': '"-c"'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'marshal_output'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'-G'"}; {'id': '60', 'type': 'if_statement', 'children': ['61', '68']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'raise_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'String commands are not supported, please use a list'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'augmented_assignment', 'children': ['76', '77'], 'value': '+='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'startupinfo'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '97']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'nt'"}, {'id': '97', 'type': 'block', 'children': ['98', '106']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'startupinfo'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'STARTUPINFO'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'augmented_assignment', 'children': ['108', '111'], 'value': '|='}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'startupinfo'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'dwFlags'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'STARTF_USESHOWWINDOW'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'Popen'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123', '128', '133', '138', '141']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'stdin'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'PIPE'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'startupinfo'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'startupinfo'}, {'id': '141', 'type': 'dictionary_splat', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'stdin'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '153']}; {'id': '148', 'type': 'attribute', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '162', '300']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'marshal_output'}; {'id': '162', 'type': 'block', 'children': ['163', '290']}, {'id': '163', 'type': 'try_statement', 'children': ['164', '286']}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'while_statement', 'children': ['166', '167']}; {'id': '166', 'type': 'True', 'children': []}, {'id': '167', 'type': 'block', 'children': ['168', '179', '225']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'marshal'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '179', 'type': 'if_statement', 'children': ['180', '197']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '190'], 'value': 'and'}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '189'], 'value': '=='}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}, {'id': '187', 'type': 'string', 'children': [], 'value': "b'code'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "''"}, {'id': '189', 'type': 'string', 'children': [], 'value': "b'error'"}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '194'], 'value': '>='}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '193', 'type': 'string', 'children': [], 'value': "b'severity'"}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_level'}, {'id': '197', 'type': 'block', 'children': ['198', '206', '214']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'call', 'children': ['200', '205']}; {'id': '200', 'type': 'attribute', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'raise_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'CommandError'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '223', '224']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '222', 'type': 'string', 'children': [], 'value': "b'data'"}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '231']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'if_statement', 'children': ['233', '236', '244']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'PY2'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'records'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'dictionary_comprehension', 'children': ['253', '277']}, {'id': '253', 'type': 'pair', 'children': ['254', '259']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '259', 'type': 'conditional_expression', 'children': ['260', '264', '269'], 'value': 'if'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273', '274']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '273', 'type': 'string', 'children': [], 'value': "'utf8'"}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '277', 'type': 'for_in_clause', 'children': ['278', '281']}; {'id': '278', 'type': 'pattern_list', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '285', 'type': 'argument_list', 'children': []}; {'id': '286', 'type': 'except_clause', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'EOFError'}; {'id': '288', 'type': 'block', 'children': ['289']}, {'id': '289', 'type': 'pass_statement', 'children': []}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '295']}; {'id': '292', 'type': 'pattern_list', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'communicate'}, {'id': '299', 'type': 'argument_list', 'children': []}; {'id': '300', 'type': 'else_clause', 'children': ['301']}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '307']}; {'id': '304', 'type': 'pattern_list', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'communicate'}, {'id': '311', 'type': 'argument_list', 'children': []}; {'id': '312', 'type': 'if_statement', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'raise_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'CommandError'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '323', 'type': 'return_statement', 'children': ['324']} | def run(self, cmd, stdin=None, marshal_output=True, **kwargs):
records = []
args = [self._executable, "-u", self._user, "-p", self._port]
if self._client:
args += ["-c", str(self._client)]
if marshal_output:
args.append('-G')
if isinstance(cmd, six.string_types):
raise ValueError('String commands are not supported, please use a list')
args += cmd
command = ' '.join(args)
startupinfo = None
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=startupinfo,
**kwargs
)
if stdin:
proc.stdin.write(six.b(stdin))
if marshal_output:
try:
while True:
record = marshal.load(proc.stdout)
if record.get(b'code', '') == b'error' and record[b'severity'] >= self._level:
proc.stdin.close()
proc.stdout.close()
raise errors.CommandError(record[b'data'], record, command)
if isinstance(record, dict):
if six.PY2:
records.append(record)
else:
records.append({str(k, 'utf8'): str(v) if isinstance(v, int) else str(v, 'utf8', errors='ignore') for k, v in record.items()})
except EOFError:
pass
stdout, stderr = proc.communicate()
else:
records, stderr = proc.communicate()
if stderr:
raise errors.CommandError(stderr, command)
return records |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'canonical_ops'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ops'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '30']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "''' Returns the given operations array sorted with duplicates removed.\n @param ops checker.Ops\n @return: checker.Ops\n '''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'new_ops'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '18']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ops'}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'lambda', 'children': ['21', '23']}, {'id': '21', 'type': 'lambda_parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '23', 'type': 'tuple', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'new_ops'} | def canonical_ops(ops):
''' Returns the given operations array sorted with duplicates removed.
@param ops checker.Ops
@return: checker.Ops
'''
new_ops = sorted(set(ops), key=lambda x: (x.entity, x.action))
return new_ops |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_from_text'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remove_duplicates'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '28', '36']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20', '23']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"arxiv:"'}, {'id': '19', 'type': 'string', 'children': [], 'value': '""'}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'REGEX'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '36', 'type': 'if_clause', 'children': ['37']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '!='}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"} | def extract_from_text(text):
return tools.remove_duplicates([re.sub("arxiv:", "", i[0],
flags=re.IGNORECASE)
for i in REGEX.findall(text) if i[0] != '']) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extractTimes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'inp'}; {'id': '6', 'type': 'block', 'children': ['7', '308', '317']}, {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'handleMatch'}, {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '11', 'type': 'block', 'children': ['12', '16', '264']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'relative'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19', '22', '40', '58', '76', '203']}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'elif_clause', 'children': ['23', '31']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '30'], 'value': '=='}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'morning'"}, {'id': '31', 'type': 'block', 'children': ['32', '36']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'elif_clause', 'children': ['41', '49']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '48'], 'value': '=='}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'afternoon'"}, {'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': 'h'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'elif_clause', 'children': ['59', '67']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '66'], 'value': '=='}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'evening'"}, {'id': '67', 'type': 'block', 'children': ['68', '72']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '19'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '90']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '84'], 'value': 'and'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '90', 'type': 'block', 'children': ['91', '99', '105', '125', '145', '199']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '96', 'type': 'expression_list', 'children': ['97', '98']}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'NumberService'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'try_statement', 'children': ['106', '121']}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '121', 'type': 'except_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'None', 'children': []}, {'id': '125', 'type': 'if_statement', 'children': ['126', '134', '139']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '133'], 'value': '=='}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'hours'"}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'augmented_assignment', 'children': ['137', '138'], 'value': '+='}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'augmented_assignment', 'children': ['143', '144'], 'value': '+='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '152']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '152', 'type': 'block', 'children': ['153', '159', '179']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'NumberService'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'try_statement', 'children': ['160', '175']}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'integer', 'children': [], 'value': '7'}, {'id': '175', 'type': 'except_clause', 'children': ['176']}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'return_statement', 'children': ['178']}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'if_statement', 'children': ['180', '188', '193']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '187'], 'value': '=='}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'hours'"}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '+='}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '193', 'type': 'else_clause', 'children': ['194']}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'augmented_assignment', 'children': ['197', '198'], 'value': '+='}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'relative'}; {'id': '202', 'type': 'True', 'children': []}, {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'id': '204', 'type': 'block', 'children': ['205', '214', '244']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'pattern_list', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '219', 'type': 'expression_list', 'children': ['220', '233']}; {'id': '220', 'type': 'binary_operator', 'children': ['221', '232'], 'value': '%'}, {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'subscript', 'children': ['225', '231']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '231', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'subscript', 'children': ['237', '243']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '243', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '244', 'type': 'try_statement', 'children': ['245', '260']}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'if_statement', 'children': ['247', '255']}, {'id': '247', 'type': 'comparison_operator', 'children': ['248', '254'], 'value': '=='}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '254', 'type': 'string', 'children': [], 'value': "'pm'"}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'augmented_assignment', 'children': ['258', '259'], 'value': '+='}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '260', 'type': 'except_clause', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'pass_statement', 'children': []}; {'id': '264', 'type': 'if_statement', 'children': ['265', '266', '283']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'relative'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'return_statement', 'children': ['268']}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '272'], 'value': '+'}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '280']}, {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'hours'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'minutes'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '283', 'type': 'else_clause', 'children': ['284']}; {'id': '284', 'type': 'block', 'children': ['285']}, {'id': '285', 'type': 'return_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '296', '301', '306', '307']}, {'id': '291', 'type': 'attribute', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '296', 'type': 'attribute', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '301', 'type': 'attribute', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': '_preprocess'}, {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'inp'}, {'id': '317', 'type': 'return_statement', 'children': ['318']}; {'id': '318', 'type': 'list_comprehension', 'children': ['319', '323']}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'handleMatch'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '323', 'type': 'for_in_clause', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '325', 'type': 'call', 'children': ['326', '331']}; {'id': '326', 'type': 'attribute', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': '_timeRegex'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'finditer'}, {'id': '331', 'type': 'argument_list', 'children': ['332']} | def extractTimes(self, inp):
def handleMatch(time):
relative = False
if not time:
return None
elif time.group(1) == 'morning':
h = 8
m = 0
elif time.group(1) == 'afternoon':
h = 12
m = 0
elif time.group(1) == 'evening':
h = 19
m = 0
elif time.group(4) and time.group(5):
h, m = 0, 0
converter = NumberService()
try:
diff = converter.parse(time.group(4))
except:
return None
if time.group(5) == 'hours':
h += diff
else:
m += diff
if time.group(6):
converter = NumberService()
try:
diff = converter.parse(time.group(7))
except:
return None
if time.group(8) == 'hours':
h += diff
else:
m += diff
relative = True
else:
t = time.group(2)
h, m = int(t.split(':')[0]) % 12, int(t.split(':')[1])
try:
if time.group(3) == 'pm':
h += 12
except IndexError:
pass
if relative:
return self.now + datetime.timedelta(hours=h, minutes=m)
else:
return datetime.datetime(
self.now.year, self.now.month, self.now.day, h, m
)
inp = self._preprocess(inp)
return [handleMatch(time) for time in self._timeRegex.finditer(inp)] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize_text'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '26', '44', '48', '65']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''Returns a serialized form of the Namepace.\n All the elements in the namespace are sorted by\n URI, joined to the associated prefix with a colon and\n separated with spaces.\n :return: bytes\n '''"}; {'id': '8', 'type': 'if_statement', 'children': ['9', '23']}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '15'], 'value': 'or'}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'is'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_uri_to_prefix'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '22'], 'value': '=='}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_uri_to_prefix'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'od'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_uri_to_prefix'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '47', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'od'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '62'], 'value': '+'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'uri'}, {'id': '61', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'od'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'uri'}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '75']}, {'id': '67', 'type': 'attribute', 'children': ['68', '74']}; {'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': 'data'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '75', 'type': 'argument_list', 'children': ['76']} | def serialize_text(self):
'''Returns a serialized form of the Namepace.
All the elements in the namespace are sorted by
URI, joined to the associated prefix with a colon and
separated with spaces.
:return: bytes
'''
if self._uri_to_prefix is None or len(self._uri_to_prefix) == 0:
return b''
od = collections.OrderedDict(sorted(self._uri_to_prefix.items()))
data = []
for uri in od:
data.append(uri + ':' + od[uri])
return ' '.join(data).encode('utf-8') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'with_zero_or_one'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '31', '40', '49', '79', '85', '91']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cardinality'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Cardinality'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'zero_or_one'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19']}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'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': 'pattern'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '27', 'type': 'string', 'children': [], 'value': '"pattern"'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'default_pattern'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'optional_pattern'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cardinality'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'make_pattern'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'group_count'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cardinality'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'compute_group_count'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '49', 'type': 'function_definition', 'children': ['50', '51', '56']}; {'id': '50', 'type': 'function_name', 'children': [], 'value': 'convert_optional'}, {'id': '51', 'type': 'parameters', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '53', 'type': 'default_parameter', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57', '68', '74']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'text'}, {'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': 'text'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '71']}, {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'convert_optional'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'optional_pattern'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'convert_optional'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'regex_group_count'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'group_count'}, {'id': '91', 'type': 'return_statement', 'children': ['92']} | def with_zero_or_one(cls, converter, pattern=None):
cardinality = Cardinality.zero_or_one
if not pattern:
pattern = getattr(converter, "pattern", cls.default_pattern)
optional_pattern = cardinality.make_pattern(pattern)
group_count = cardinality.compute_group_count(pattern)
def convert_optional(text, m=None):
if text:
text = text.strip()
if not text:
return None
return converter(text)
convert_optional.pattern = optional_pattern
convert_optional.regex_group_count = group_count
return convert_optional |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stats_keyboard'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '27', '35', '48', '63', '72', '200', '229', '387']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': '<'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'expression_list', 'children': ['17', '18']}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'deltas'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '24', 'type': 'expression_list', 'children': ['25', '26']}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'pattern_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sessions'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '32', 'type': 'expression_list', 'children': ['33', '34']}, {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'UNBROKEN_DELTA'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'seconds'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'KeyboardSessionMaxDelta'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'blank'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'lambda', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'collated'}; {'id': '66', 'type': 'list', 'children': ['67'], 'value': '[blank.copy()]'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'blank'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '75', 'type': 'block', 'children': ['76', '170', '181', '194']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '78', 'type': 'block', 'children': ['79', '122', '130', '137']}, {'id': '79', 'type': 'if_statement', 'children': ['80', '110']}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81'], 'value': '()'}, {'id': '81', 'type': 'boolean_operator', 'children': ['82', '101'], 'value': 'or'}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '92'], 'value': 'or'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '!='}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"dt"'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '!='}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'minute'}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"dt"'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'minute'}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '!='}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'hour'}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"dt"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'collated'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'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': 'blank'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'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': 'delta'}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '-'}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"dt"'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'prev_dt'}; {'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': 'deltas'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '137', 'type': 'if_statement', 'children': ['138', '141', '146']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '>'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'UNBROKEN_DELTA'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '145', 'type': 'None', 'children': []}; {'id': '146', 'type': 'else_clause', 'children': ['147']}, {'id': '147', 'type': 'block', 'children': ['148', '163']}; {'id': '148', 'type': 'if_statement', 'children': ['149', '151']}, {'id': '149', 'type': 'not_operator', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '151', 'type': 'block', 'children': ['152', '156']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '155', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sessions'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'session'}, {'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': 'session'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '178']}; {'id': '172', 'type': 'subscript', 'children': ['173', '177']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'collated'}, {'id': '175', 'type': 'unary_operator', 'children': ['176'], 'value': '-'}; {'id': '176', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '177', 'type': 'string', 'children': [], 'value': '"dt"'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"dt"'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'augmented_assignment', 'children': ['183', '193'], 'value': '+='}, {'id': '183', 'type': 'subscript', 'children': ['184', '190']}; {'id': '184', 'type': 'subscript', 'children': ['185', '189']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'collated'}, {'id': '187', 'type': 'unary_operator', 'children': ['188'], 'value': '-'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'string', 'children': [], 'value': '"keys"'}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '192', 'type': 'string', 'children': [], 'value': '"realkey"'}, {'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': 'prev_dt'}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '199', 'type': 'string', 'children': [], 'value': '"dt"'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'longest_session'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '215']}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'sessions'}; {'id': '208', 'type': 'list', 'children': ['209'], 'value': '[[datetime.timedelta()]]'}, {'id': '209', 'type': 'list', 'children': ['210'], 'value': '[datetime.timedelta()]'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '214', 'type': 'argument_list', 'children': []}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '217', 'type': 'lambda', 'children': ['218', '220']}; {'id': '218', 'type': 'lambda_parameters', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '228', 'type': 'argument_list', 'children': []}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '232', 'type': 'conditional_expression', 'children': ['233', '250', '253'], 'value': 'if'}, {'id': '233', 'type': 'list', 'children': ['234'], 'value': '[\r\n ("Average interval between combos",\r\n sum(deltas, datetime.timedelta()) / len(deltas)),\r\n ]'}; {'id': '234', 'type': 'tuple', 'children': ['235', '236']}, {'id': '235', 'type': 'string', 'children': [], 'value': '"Average interval between combos"'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '246'], 'value': '/'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'deltas'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '245', 'type': 'argument_list', 'children': []}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '=='}, {'id': '251', 'type': 'string', 'children': [], 'value': '"combos"'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '253', 'type': 'list', 'children': ['254', '281', '297', '307', '326', '354', '365', '373'], 'value': '[\r\n ("Keys per hour",\r\n int(3600 * len(events) / timedelta_seconds(events[-1]["dt"] - events[0]["dt"]))),\r\n ("Average interval between keys",\r\n sum(deltas, datetime.timedelta()) / len(deltas)),\r\n ("Typing sessions (key interval < %ss)" % UNBROKEN_DELTA.seconds,\r\n len(sessions)),\r\n ("Average keys in session",\r\n sum(len(x) + 1 for x in sessions) / len(sessions)),\r\n ("Average session duration", sum((sum(x, datetime.timedelta())\r\n for x in sessions), datetime.timedelta()) / len(sessions)),\r\n ("Longest session duration",\r\n sum(longest_session, datetime.timedelta())),\r\n ("Keys in longest session",\r\n len(longest_session) + 1),\r\n ("Most keys in session",\r\n max(len(x) + 1 for x in sessions)),\r\n ]'}; {'id': '254', 'type': 'tuple', 'children': ['255', '256']}, {'id': '255', 'type': 'string', 'children': [], 'value': '"Keys per hour"'}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'binary_operator', 'children': ['260', '266'], 'value': '/'}; {'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '*'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '3600'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'timedelta_seconds'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '276'], 'value': '-'}; {'id': '270', 'type': 'subscript', 'children': ['271', '275']}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '273', 'type': 'unary_operator', 'children': ['274'], 'value': '-'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '275', 'type': 'string', 'children': [], 'value': '"dt"'}; {'id': '276', 'type': 'subscript', 'children': ['277', '280']}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '280', 'type': 'string', 'children': [], 'value': '"dt"'}, {'id': '281', 'type': 'tuple', 'children': ['282', '283']}; {'id': '282', 'type': 'string', 'children': [], 'value': '"Average interval between keys"'}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '293'], 'value': '/'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '292', 'type': 'argument_list', 'children': []}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'deltas'}, {'id': '297', 'type': 'tuple', 'children': ['298', '303']}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '%'}, {'id': '299', 'type': 'string', 'children': [], 'value': '"Typing sessions (key interval < %ss)"'}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'UNBROKEN_DELTA'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'seconds'}, {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'sessions'}, {'id': '307', 'type': 'tuple', 'children': ['308', '309']}; {'id': '308', 'type': 'string', 'children': [], 'value': '"Average keys in session"'}, {'id': '309', 'type': 'binary_operator', 'children': ['310', '322'], 'value': '/'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '312', 'type': 'generator_expression', 'children': ['313', '319']}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '318'], 'value': '+'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '318', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '319', 'type': 'for_in_clause', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'sessions'}; {'id': '322', 'type': 'call', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'sessions'}; {'id': '326', 'type': 'tuple', 'children': ['327', '328']}, {'id': '327', 'type': 'string', 'children': [], 'value': '"Average session duration"'}; {'id': '328', 'type': 'binary_operator', 'children': ['329', '350'], 'value': '/'}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '331', 'type': 'argument_list', 'children': ['332', '345']}; {'id': '332', 'type': 'generator_expression', 'children': ['333', '342']}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '335', 'type': 'argument_list', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '341', 'type': 'argument_list', 'children': []}; {'id': '342', 'type': 'for_in_clause', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'sessions'}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '349', 'type': 'argument_list', 'children': []}; {'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': 'sessions'}; {'id': '354', 'type': 'tuple', 'children': ['355', '356']}, {'id': '355', 'type': 'string', 'children': [], 'value': '"Longest session duration"'}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '358', 'type': 'argument_list', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'longest_session'}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '364', 'type': 'argument_list', 'children': []}, {'id': '365', 'type': 'tuple', 'children': ['366', '367']}; {'id': '366', 'type': 'string', 'children': [], 'value': '"Keys in longest session"'}, {'id': '367', 'type': 'binary_operator', 'children': ['368', '372'], 'value': '+'}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'longest_session'}; {'id': '372', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '373', 'type': 'tuple', 'children': ['374', '375']}; {'id': '374', 'type': 'string', 'children': [], 'value': '"Most keys in session"'}, {'id': '375', 'type': 'call', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '377', 'type': 'generator_expression', 'children': ['378', '384']}; {'id': '378', 'type': 'binary_operator', 'children': ['379', '383'], 'value': '+'}, {'id': '379', 'type': 'call', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '383', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '384', 'type': 'for_in_clause', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'sessions'}, {'id': '387', 'type': 'return_statement', 'children': ['388']}; {'id': '388', 'type': 'expression_list', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'stats'} | def stats_keyboard(events, table):
if len(events) < 2: return [], []
deltas, prev_dt = [], None
sessions, session = [], None
UNBROKEN_DELTA = datetime.timedelta(seconds=conf.KeyboardSessionMaxDelta)
blank = collections.defaultdict(lambda: collections.defaultdict(int))
collated = [blank.copy()]
for e in events:
if prev_dt:
if (prev_dt.second != e["dt"].second
or prev_dt.minute != e["dt"].minute or prev_dt.hour != e["dt"].hour):
collated.append(blank.copy())
delta = e["dt"] - prev_dt
deltas.append(delta)
if delta > UNBROKEN_DELTA:
session = None
else:
if not session:
session = []
sessions.append(session)
session.append(delta)
collated[-1]["dt"] = e["dt"]
collated[-1]["keys"][e["realkey"]] += 1
prev_dt = e["dt"]
longest_session = max(sessions + [[datetime.timedelta()]], key=lambda x: sum(x, datetime.timedelta()))
stats = [
("Average interval between combos",
sum(deltas, datetime.timedelta()) / len(deltas)),
] if "combos" == table else [
("Keys per hour",
int(3600 * len(events) / timedelta_seconds(events[-1]["dt"] - events[0]["dt"]))),
("Average interval between keys",
sum(deltas, datetime.timedelta()) / len(deltas)),
("Typing sessions (key interval < %ss)" % UNBROKEN_DELTA.seconds,
len(sessions)),
("Average keys in session",
sum(len(x) + 1 for x in sessions) / len(sessions)),
("Average session duration", sum((sum(x, datetime.timedelta())
for x in sessions), datetime.timedelta()) / len(sessions)),
("Longest session duration",
sum(longest_session, datetime.timedelta())),
("Keys in longest session",
len(longest_session) + 1),
("Most keys in session",
max(len(x) + 1 for x in sessions)),
]
return stats, collated |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_perseus'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path_or_file'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'main_columns'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'separator'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'separator'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'convert_bool_to_category'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'numerical_annotation_rows'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'block', 'children': ['22', '30', '46', '57', '61', '73', '100', '181', '234', '248', '280']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '37']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'Column Name'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'column_names'}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_level_values'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'Column Name'"}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '60', 'type': 'dictionary', 'children': []}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'main_columns'}; {'id': '64', 'type': 'conditional_expression', 'children': ['65', '69', '72'], 'value': 'if'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_infer_main_columns'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'main_columns'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'main_columns'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '90']}, {'id': '79', 'type': 'conditional_expression', 'children': ['80', '81', '86'], 'value': 'if'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'E'"}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': 'in'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'main_columns'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dtype_to_perseus'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '94']}, {'id': '91', 'type': 'pattern_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dtypes'}; {'id': '100', 'type': 'for_statement', 'children': ['101', '104', '110']}, {'id': '101', 'type': 'pattern_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '110', 'type': 'block', 'children': ['111', '125']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'valid_values'}; {'id': '114', 'type': 'list_comprehension', 'children': ['115', '116', '121']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '121', 'type': 'if_clause', 'children': ['122']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '124', 'type': 'None', 'children': []}, {'id': '125', 'type': 'if_statement', 'children': ['126', '145']}; {'id': '126', 'type': 'boolean_operator', 'children': ['127', '133'], 'value': 'and'}, {'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': 'valid_values'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '135', 'type': 'generator_expression', 'children': ['136', '142']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': 'is'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'valid_values'}, {'id': '145', 'type': 'block', 'children': ['146', '154']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'Type'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'M'"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '159', 'type': 'call', 'children': ['160', '165']}; {'id': '160', 'type': 'attribute', 'children': ['161', '164']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'apply'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'lambda', 'children': ['167', '169']}, {'id': '167', 'type': 'lambda_parameters', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '173', 'type': 'generator_expression', 'children': ['174', '178']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'xs'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'convert_bool_to_category'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'for_statement', 'children': ['185', '188', '194']}, {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'if_statement', 'children': ['196', '208']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': 'is'}, {'id': '197', 'type': 'subscript', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'dtypes'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'string', 'children': [], 'value': "'bool'"}; {'id': '208', 'type': 'block', 'children': ['209', '217', '225']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': '_df'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '224']}, {'id': '219', 'type': 'subscript', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '233']}, {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '231', 'type': 'unary_operator', 'children': ['232'], 'value': '~'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '233', 'type': 'string', 'children': [], 'value': "''"}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'annotation_row_names'}, {'id': '237', 'type': 'binary_operator', 'children': ['238', '246'], 'value': '-'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '246', 'type': 'set', 'children': ['247']}, {'id': '247', 'type': 'string', 'children': [], 'value': "'Column Name'"}; {'id': '248', 'type': 'for_statement', 'children': ['249', '250', '251']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'annotation_row_names'}, {'id': '251', 'type': 'block', 'children': ['252', '261']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'annotation_type'}, {'id': '255', 'type': 'conditional_expression', 'children': ['256', '257', '260'], 'value': 'if'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'N'"}, {'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': 'in'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'numerical_annotation_rows'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'C'"}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '272']}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'string', 'children': [], 'value': "'{}:{}'"}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'annotation_type'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': '_df'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'get_level_values'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '280', 'type': 'with_statement', 'children': ['281', '291']}, {'id': '281', 'type': 'with_clause', 'children': ['282']}; {'id': '282', 'type': 'with_item', 'children': ['283']}, {'id': '283', 'type': 'as_pattern', 'children': ['284', '289']}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'PathOrFile'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'path_or_file'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '289', 'type': 'as_pattern_target', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '291', 'type': 'block', 'children': ['292', '306', '320']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '305'], 'value': '+'}, {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'separator'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'column_names'}, {'id': '305', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '306', 'type': 'for_statement', 'children': ['307', '310', '315', '319']}, {'id': '307', 'type': 'pattern_list', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '314', 'type': 'argument_list', 'children': []}, {'id': '315', 'type': 'ERROR', 'children': ['316']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '319', 'type': 'block', 'children': [], 'value': ''}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': '_df'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'to_csv'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327', '330', '333']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '329', 'type': 'None', 'children': []}; {'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '332', 'type': 'False', 'children': []}, {'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'sep'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'separator'} | def to_perseus(df, path_or_file, main_columns=None,
separator=separator,
convert_bool_to_category=True,
numerical_annotation_rows = set([])):
_df = df.copy()
if not _df.columns.name:
_df.columns.name = 'Column Name'
column_names = _df.columns.get_level_values('Column Name')
annotations = {}
main_columns = _infer_main_columns(_df) if main_columns is None else main_columns
annotations['Type'] = ['E' if column_names[i] in main_columns else dtype_to_perseus(dtype)
for i, dtype in enumerate(_df.dtypes)]
for i, column in enumerate(_df.columns):
valid_values = [value for value in _df[column] if value is not None]
if len(valid_values) > 0 and all(type(value) is list for value in valid_values):
annotations['Type'][i] = 'M'
_df[column] = _df[column].apply(lambda xs: ';'.join(str(x) for x in xs))
if convert_bool_to_category:
for i, column in enumerate(_df.columns):
if _df.dtypes[i] is np.dtype('bool'):
values = _df[column].values
_df[column][values] = '+'
_df[column][~values] = ''
annotation_row_names = set(_df.columns.names) - {'Column Name'}
for name in annotation_row_names:
annotation_type = 'N' if name in numerical_annotation_rows else 'C'
annotations['{}:{}'.format(annotation_type, name)] = _df.columns.get_level_values(name)
with PathOrFile(path_or_file, 'w') as f:
f.write(separator.join(column_names) + '\n')
for name, values in annotations.items():
f.write('
_df.to_csv(f, header=None, index=False, sep=separator) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_your_job'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '65', '71', '80', '153']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_intended_direction'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '32']}, {'id': '17', 'type': 'boolean_operator', 'children': ['18', '25'], 'value': 'and'}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'target_x'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'current_x'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '=='}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'target_y'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '32', 'type': 'block', 'children': ['33', '64']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '42']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '41'], 'value': '=='}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'block', 'children': ['43', '52']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"TARGET ACQUIRED"'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '63'], 'value': '+'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'string', 'children': [], 'value': '": TARGET ACQUIRED"'}; {'id': '64', 'type': 'return_statement', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '70'], 'value': '+='}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'num_steps'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'accessible'}; {'id': '74', 'type': 'list', 'children': ['75', '76', '77', '78', '79'], 'value': "['\\\\', '-', '|', '/', '.']"}, {'id': '75', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '77', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '96']}, {'id': '81', 'type': 'boolean_operator', 'children': ['82', '89'], 'value': 'and'}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '86'], 'value': 'and'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '!='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '!='}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'backtrack'}, {'id': '93', 'type': 'list', 'children': ['94', '95'], 'value': '[0,0]'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '107']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '106'], 'value': '>'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'randint'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '126']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '125'], 'value': 'in'}; {'id': '110', 'type': 'call', 'children': ['111', '116']}, {'id': '111', 'type': 'attribute', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'grd'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'get_tile'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '122']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '121'], 'value': '+'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'current_y'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'current_x'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'accessible'}; {'id': '126', 'type': 'block', 'children': ['127', '133', '152']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'augmented_assignment', 'children': ['129', '132'], 'value': '+='}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'y'}, {'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': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}, {'id': '139', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '146'], 'value': '+'}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '+'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '145', 'type': 'string', 'children': [], 'value': '": randomly moving Y axis "'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'num_steps'}; {'id': '152', 'type': 'return_statement', 'children': []}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '=='}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'block', 'children': ['158', '200', '241', '283']}; {'id': '158', 'type': 'if_statement', 'children': ['159', '176']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '175'], 'value': 'in'}; {'id': '160', 'type': 'call', 'children': ['161', '166']}, {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'grd'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_tile'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '174'], 'value': '+'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'accessible'}; {'id': '176', 'type': 'block', 'children': ['177', '183']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'augmented_assignment', 'children': ['179', '182'], 'value': '+='}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'ERROR', 'children': ['184', '187', '188']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}, {'id': '187', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '198'], 'value': '=='}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '193', '197'], 'value': '+'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '193', 'type': 'ERROR', 'children': ['194', '195', '196']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'move'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'return'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'elif'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '198', 'type': 'unary_operator', 'children': ['199'], 'value': '-'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '218']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '217'], 'value': 'in'}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'grd'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'get_tile'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '216'], 'value': '-'}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'accessible'}; {'id': '218', 'type': 'block', 'children': ['219', '225']}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'augmented_assignment', 'children': ['221', '224'], 'value': '-='}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '225', 'type': 'ERROR', 'children': ['226', '229', '230']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '240'], 'value': '=='}, {'id': '231', 'type': 'binary_operator', 'children': ['232', '235', '239'], 'value': '+'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '235', 'type': 'ERROR', 'children': ['236', '237', '238']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'move'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'return'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'elif'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '240', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '241', 'type': 'if_statement', 'children': ['242', '259']}; {'id': '242', 'type': 'comparison_operator', 'children': ['243', '258'], 'value': 'in'}, {'id': '243', 'type': 'call', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'grd'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'get_tile'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '255']}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '254'], 'value': '+'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'accessible'}, {'id': '259', 'type': 'block', 'children': ['260', '266']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'augmented_assignment', 'children': ['262', '265'], 'value': '+='}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'current_y'}, {'id': '265', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '266', 'type': 'ERROR', 'children': ['267', '270', '271']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '271', 'type': 'comparison_operator', 'children': ['272', '281'], 'value': '=='}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '276', '280'], 'value': '+'}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '276', 'type': 'ERROR', 'children': ['277', '278', '279']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'move'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'return'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'elif'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '281', 'type': 'unary_operator', 'children': ['282'], 'value': '-'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '283', 'type': 'if_statement', 'children': ['284', '301']}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '300'], 'value': 'in'}, {'id': '285', 'type': 'call', 'children': ['286', '291']}; {'id': '286', 'type': 'attribute', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'grd'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'get_tile'}, {'id': '291', 'type': 'argument_list', 'children': ['292', '297']}; {'id': '292', 'type': 'binary_operator', 'children': ['293', '296'], 'value': '-'}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'current_y'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'current_x'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'accessible'}, {'id': '301', 'type': 'block', 'children': ['302', '308']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'augmented_assignment', 'children': ['304', '307'], 'value': '-='}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'current_y'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '308', 'type': 'ERROR', 'children': ['309', '312', '313']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'lg_mv'}; {'id': '312', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '317', '319'], 'value': '+'}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '317', 'type': 'ERROR', 'children': ['318']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'move'}, {'id': '319', 'type': 'call', 'children': ['320', '342']}; {'id': '320', 'type': 'attribute', 'children': ['321', '341']}, {'id': '321', 'type': 'attribute', 'children': ['322', '338', '340']}; {'id': '322', 'type': 'call', 'children': ['323', '330']}, {'id': '323', 'type': 'attribute', 'children': ['324', '329']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326', '328']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'return'}; {'id': '326', 'type': 'ERROR', 'children': ['327']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'grd'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'set_tile'}; {'id': '330', 'type': 'argument_list', 'children': ['331', '334', '337']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'start_y'}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'start_x'}, {'id': '337', 'type': 'string', 'children': [], 'value': "'A'"}; {'id': '338', 'type': 'ERROR', 'children': ['339']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'grd'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}, {'id': '343', 'type': 'call', 'children': ['344', '349']}; {'id': '344', 'type': 'attribute', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '349', 'type': 'argument_list', 'children': ['350', '355']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '354', 'type': 'argument_list', 'children': []}, {'id': '355', 'type': 'string', 'children': [], 'value': "'agent.txt'"} | def do_your_job(self):
y,x = self.get_intended_direction()
if self.target_x == self.current_x and self.target_y == self.current_y:
if len(self.results) == 0:
self.results.append("TARGET ACQUIRED")
self.lg_mv(2, self.name + ": TARGET ACQUIRED" )
return
self.num_steps += 1
accessible = ['\\', '-', '|', '/', '.']
if y != 0 and x != 0 and self.backtrack == [0,0]:
if random.randint(1,10) > 6:
if self.grd.get_tile(self.current_y + y, self.current_x) in accessible:
self.current_y += y
self.lg_mv(3, self.name + ": randomly moving Y axis " + str(self.num_steps) )
return
if x == 1:
if self.grd.get_tile(self.current_y, self.current_x + 1) in accessible:
self.current_x += 1
self.lg_mv(3, self.name + ": move
return
elif x == -1:
if self.grd.get_tile(self.current_y, self.current_x - 1) in accessible:
self.current_x -= 1
self.lg_mv(3, self.name + ": move
return
elif y == 1:
if self.grd.get_tile(self.current_y + 1, self.current_x) in accessible:
self.current_y += 1
self.lg_mv(3, self.name + ": move
return
elif y == -1:
if self.grd.get_tile(self.current_y - 1, self.current_x) in accessible:
self.current_y -= 1
self.lg_mv(3, self.name + ": move
return
self.grd.set_tile(self.start_y, self.start_x, 'A')
self.grd.save(os.path.join(os.getcwd(), 'agent.txt')) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_filelist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'opFile'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'opFormat'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '9', 'type': 'string', 'children': [], 'value': "','"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '12', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '13', 'type': 'block', 'children': ['14', '25', '48']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'op_folder'}, {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'opFile'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'op_folder'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '40']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'op_folder'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'makedirs'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'op_folder'}; {'id': '48', 'type': 'with_statement', 'children': ['49', '59']}, {'id': '49', 'type': 'with_clause', 'children': ['50']}; {'id': '50', 'type': 'with_item', 'children': ['51']}, {'id': '51', 'type': 'as_pattern', 'children': ['52', '57']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'opFile'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '57', 'type': 'as_pattern_target', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fout'}, {'id': '59', 'type': 'block', 'children': ['60', '69', '82', '89']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fout'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'}, {'id': '67', 'type': 'string', 'children': [], 'value': '"fullFilename"'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'colHeading'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'opFormat'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'fout'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'colHeading'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'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': 'fout'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '94']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'filelist'}; {'id': '94', 'type': 'block', 'children': ['95', '105', '215']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '104'], 'value': '+'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '103'], 'value': '+'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '105', 'type': 'try_statement', 'children': ['106', '208']}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fld'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'opFormat'}; {'id': '110', 'type': 'block', 'children': ['111', '135', '157', '184']}, {'id': '111', 'type': 'if_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'fld'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '134'], 'value': '+'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '133'], 'value': '+'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '125'], 'value': '+'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '+'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'qu'}, {'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': 'os'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '139']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '=='}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'fld'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"date"'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '156'], 'value': '+'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '155'], 'value': '+'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '149'], 'value': '+'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'qu'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'GetDateAsString'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'delim'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '161']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '=='}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fld'}; {'id': '160', 'type': 'string', 'children': [], 'value': '"size"'}, {'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': 'line'}, {'id': '165', 'type': 'binary_operator', 'children': ['166', '183'], 'value': '+'}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '182'], 'value': '+'}, {'id': '167', 'type': 'binary_operator', 'children': ['168', '171'], 'value': '+'}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '+'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'qu'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '180']}, {'id': '175', 'type': 'attribute', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'getsize'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'qu'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188']}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'fld'}, {'id': '187', 'type': 'string', 'children': [], 'value': '"path"'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '207'], 'value': '+'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '206'], 'value': '+'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '198'], 'value': '+'}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'qu'}; {'id': '198', 'type': 'call', 'children': ['199', '204']}, {'id': '199', 'type': 'attribute', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'qu'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'id': '208', 'type': 'except_clause', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'augmented_assignment', 'children': ['213', '214'], 'value': '+='}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '215', 'type': 'try_statement', 'children': ['216', '245']}; {'id': '216', 'type': 'block', 'children': ['217', '238']}, {'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': 'fout'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '236']}, {'id': '227', 'type': 'attribute', 'children': ['228', '235']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '234', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'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': 'fout'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '245', 'type': 'except_clause', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'IOError'}, {'id': '247', 'type': 'block', 'children': ['248']} | def save_filelist(self, opFile, opFormat, delim=',', qu='"'):
op_folder = os.path.dirname(opFile)
if op_folder is not None:
if not os.path.exists(op_folder):
os.makedirs(op_folder)
with open(opFile,'w') as fout:
fout.write("fullFilename" + delim)
for colHeading in opFormat:
fout.write(colHeading + delim)
fout.write('\n')
for f in self.filelist:
line = qu + f + qu + delim
try:
for fld in opFormat:
if fld == "name":
line = line + qu + os.path.basename(f) + qu + delim
if fld == "date":
line = line + qu + self.GetDateAsString(f) + qu + delim
if fld == "size":
line = line + qu + str(os.path.getsize(f)) + qu + delim
if fld == "path":
line = line + qu + os.path.dirname(f) + qu + delim
except IOError:
line += '\n'
try:
fout.write (str(line.encode('ascii', 'ignore').decode('utf-8')))
fout.write ('\n')
except IOError:
pass |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'type'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverages'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '23', '27', '44', '61', '78']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverages'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}, {'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': 'variant_probe_coverages'}, {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[variant_probe_coverages]'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverages'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'calls'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverage'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverages'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'calls'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'}; {'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': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_type_variant_probe_coverages'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'variant_probe_coverage'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'variant'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hom_alt_calls'}, {'id': '47', 'type': 'list_comprehension', 'children': ['48', '49', '52']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'calls'}; {'id': '52', 'type': 'if_clause', 'children': ['53']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '60'], 'value': '>'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '59', 'type': 'string', 'children': [], 'value': '"genotype"'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'het_calls'}; {'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'calls'}, {'id': '69', 'type': 'if_clause', 'children': ['70']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '77'], 'value': '=='}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"genotype"'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80', '104', '130']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'hom_alt_calls'}; {'id': '80', 'type': 'block', 'children': ['81', '100']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'hom_alt_calls'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '97']}, {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'lambda', 'children': ['90', '92']}; {'id': '90', 'type': 'lambda_parameters', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '95', 'type': 'string', 'children': [], 'value': '"info"'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"conf"'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '99', 'type': 'True', 'children': []}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'hom_alt_calls'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'elif_clause', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'het_calls'}; {'id': '106', 'type': 'block', 'children': ['107', '126']}, {'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': 'het_calls'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '123']}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'lambda', 'children': ['116', '118']}; {'id': '116', 'type': 'lambda_parameters', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '121', 'type': 'string', 'children': [], 'value': '"info"'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"conf"'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '125', 'type': 'True', 'children': []}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'het_calls'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'else_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132', '151']}; {'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': 'calls'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '148']}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '140', 'type': 'lambda', 'children': ['141', '143']}, {'id': '141', 'type': 'lambda_parameters', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '143', 'type': 'subscript', 'children': ['144', '147']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"info"'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"conf"'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '150', 'type': 'True', 'children': []}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'calls'} | def type(self, variant_probe_coverages, variant=None):
if not isinstance(variant_probe_coverages, list):
variant_probe_coverages = [variant_probe_coverages]
calls = []
for variant_probe_coverage in variant_probe_coverages:
calls.append(
self._type_variant_probe_coverages(
variant_probe_coverage, variant))
hom_alt_calls = [c for c in calls if sum(c["genotype"]) > 1]
het_calls = [c for c in calls if sum(c["genotype"]) == 1]
if hom_alt_calls:
hom_alt_calls.sort(key=lambda x: x["info"]["conf"], reverse=True)
return hom_alt_calls[0]
elif het_calls:
het_calls.sort(key=lambda x: x["info"]["conf"], reverse=True)
return het_calls[0]
else:
calls.sort(key=lambda x: x["info"]["conf"], reverse=True)
return calls[0] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'versions'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '17']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'tool_name'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'versions'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '24']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'versions'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'tool_name'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_log'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Using tool \'%s\', %s"'}; {'id': '32', 'type': 'tuple', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tool_name'} | def process(self, versions):
for tool_name in sorted(versions.keys()):
version = versions[tool_name]
self._log("Using tool '%s', %s" % (tool_name, version)) |